Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gui/src/app/guidedSetupProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ export const proposalRequestLimits = {
maxXMLTVBytes: 12 * 1024 * 1024,
} as const

export type GuidedSetupCheck = {
Kind: 'logos' | 'categories'
Status: 'ok' | 'attention' | 'unavailable'
Headline: string
Details: string[]
}

export type GuidedSetupProposal = {
Version: 'guided-setup/proposal/v1'
Status: 'PROPOSAL_READY'
Expand Down Expand Up @@ -79,6 +86,7 @@ export type GuidedSetupSourceSetProposal = {
BlockingReasons: string[]
}
Warnings: Array<{ Code: string; Message: string }>
Checks?: GuidedSetupCheck[]
Safety: {
PublicationState: 'CandidateOnly'
AcceptedStateMutation: 'none'
Expand Down
18 changes: 17 additions & 1 deletion gui/src/pages/GuidedSetupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BookOpen, CheckCircle2, FileText, FolderOpen, ListVideo } from 'lucide-
import {
acceptGuidedSetupSourceSetProposal,
submitGuidedSetupSourceSetProposal,
type GuidedSetupCheck,
type GuidedSetupSourceDraft,
type GuidedSetupSourceSetAcceptance,
type GuidedSetupSourceSetProposal,
Expand Down Expand Up @@ -106,6 +107,19 @@ type GuideBindingSelection = {
explicitlyUnbound: boolean
}

function ProposalCheckRow({ check }: { check: GuidedSetupCheck }) {
const [open, setOpen] = useState(false)
const name = check.Kind === 'logos' ? 'Logos' : 'Categories'
const state = check.Status === 'ok' ? 'OK' : check.Status === 'attention' ? 'Needs a look' : 'Not available'
return (
<li>
<strong>{name}: {state}.</strong> {check.Headline}
{check.Details.length > 0 ? <> <button aria-expanded={open} className="button" type="button" onClick={() => setOpen(!open)}>{open ? 'Hide details' : 'Details'}</button></> : null}
{open ? <ul>{check.Details.map((line, index) => <li key={index}>{line}</li>)}</ul> : null}
</li>
)
}

function BrowserGuidedSetupPage({
sourceSetProposalSubmitter,
sourceSetAcceptanceSubmitter,
Expand All @@ -120,6 +134,7 @@ function BrowserGuidedSetupPage({
const [bindings, setBindings] = useState<Record<string, GuideBindingSelection>>({})
const [proposal, setProposal] = useState<GuidedSetupSourceSetProposal | null>(null)
const [accepted, setAccepted] = useState<GuidedSetupSourceSetAcceptance | null>(null)
const shownWarnings = (proposal?.Warnings ?? []).filter((warning) => !(warning.Code === 'logo-check' && proposal?.Checks?.some((check) => check.Kind === 'logos')))
const [acknowledged, setAcknowledged] = useState(false)
const [error, setError] = useState<string | null>(null)
const proposalErrorRef = useRef<HTMLParagraphElement>(null)
Expand Down Expand Up @@ -337,7 +352,8 @@ function BrowserGuidedSetupPage({
<div><dt>Needs review</dt><dd>{proposal.Proposal.AmbiguityCount}</dd></div>
<div><dt>Unbound guides</dt><dd>{proposal.Proposal.UnboundGuideCount}</dd></div>
</dl>
{proposal.Warnings.length > 0 ? <ul>{proposal.Warnings.map((warning) => <li key={warning.Code}>{warning.Message}</li>)}</ul> : <p>No proposal warnings.</p>}
{proposal.Checks && proposal.Checks.length > 0 ? <><h3>Checks before you accept</h3><ul>{proposal.Checks.map((check) => <ProposalCheckRow check={check} key={check.Kind} />)}</ul></> : null}
{shownWarnings.length > 0 ? <ul>{shownWarnings.map((warning) => <li key={warning.Code}>{warning.Message}</li>)}</ul> : <p>No proposal warnings.</p>}
{proposal.Proposal.BlockingReasons.length > 0 ? <p role="alert">Acceptance is blocked until the review blockers are resolved.</p> : null}
{!accepted ? <div className="saved-lineup-action-row"><label className="saved-lineup-acknowledgement"><input type="checkbox" checked={acknowledged} onChange={(event) => setAcknowledged(event.target.checked)} /> I reviewed these results and want to accept this exact proposal.</label><button aria-busy={accepting} className="button button-primary" disabled={!proposal.Proposal.CanAccept || !acknowledged || accepting} type="button" onClick={() => void accept()}>{accepting ? 'Accepting…' : 'Accept reviewed proposal'}</button></div> : null}
</div>
Expand Down
24 changes: 24 additions & 0 deletions gui/src/test/guided-setup-browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ const accepted: GuidedSetupSourceSetAcceptance = {
}

describe('browser Guided Setup proposal and acceptance', () => {
it('shows the logo and category checks in plain words, hides details until asked, and still needs the acknowledgement', async () => {
const user = userEvent.setup()
const withChecks: GuidedSetupSourceSetProposal = {
...readyProposal,
Warnings: [{ Code: 'logo-check', Message: 'Logo check: 1 of 2 channels have no public https logo. Pin one with Set-ChannelForgeLogoPin.' }],
Checks: [
{ Kind: 'logos', Status: 'attention', Headline: '1 of 2 channels have no public logo. You can accept, or fix this first (see Details).', Details: ['Empty: One.'] },
{ Kind: 'categories', Status: 'unavailable', Headline: 'Category check could not run. You can still accept.', Details: [] },
],
}
const submitter = vi.fn<GuidedSetupSourceSetSubmitter>().mockResolvedValue(withChecks)
render(<GuidedSetupPage pickerAvailable={false} sourceSetProposalSubmitter={submitter} sourceSetAcceptanceSubmitter={vi.fn()} />)
await user.upload(screen.getAllByLabelText('Choose playlist')[0], new File(['#EXTM3U\n#EXTINF:-1,One\nhttps://example.invalid/one\n'], 'channels.m3u'))
await user.click(screen.getByRole('button', { name: 'Analyze source set' }))

expect(await screen.findByText(/1 of 2 channels have no public logo/)).toBeInTheDocument()
expect(screen.getByText('Category check could not run. You can still accept.')).toBeInTheDocument()
expect(screen.queryByText(/Set-ChannelForgeLogoPin/)).not.toBeInTheDocument()
expect(screen.queryByText('Empty: One.')).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Details' }))
expect(screen.getByText('Empty: One.')).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Accept reviewed proposal' })).toBeDisabled()
})

it('reviews multiple browser sources, submits explicit guide bindings, and accepts only after acknowledgement', async () => {
const user = userEvent.setup()
const submitter = vi.fn<GuidedSetupSourceSetSubmitter>().mockResolvedValue(readyProposal)
Expand Down
40 changes: 40 additions & 0 deletions src/ChannelForge/Private/Get-ChannelForgeGuidedSetupChecks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function Get-ChannelForgeGuidedSetupChecks {
<#
.SYNOPSIS
Builds the logo and category checks shown before a beginner accepts (guided-setup/checks/v1).

.DESCRIPTION
Report only. Reads the candidate and returns plain headlines plus the module's own summary
lines. It never changes the candidate and is never hashed. A failing category report gives
an 'unavailable' row and no path, URL or id.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)][object]$Candidate,
[Parameter(Mandatory)][string]$RepositoryRoot
)

$accept = 'You can accept, or fix this first (see Details).'
$checks = [System.Collections.Generic.List[object]]::new()

$logo = $Candidate.LogoReport
$missing = [int]$logo.Empty + [int]$logo.NotHttps + [int]$logo.PrivateAddress
$total = $missing + [int]$logo.Public
$logoStatus = if ($missing -gt 0) { 'attention' } else { 'ok' }
$logoHeadline = if ($missing -gt 0) { "$missing of $total channels have no public logo. $accept" } else { 'Every channel has a public logo. Looks fine.' }
$logoDetails = @(if ($logo.Warning) { [string]$logo.Warning })
[void]$checks.Add([pscustomobject][ordered]@{ Kind = 'logos'; Status = $logoStatus; Headline = $logoHeadline; Details = $logoDetails })

try {
$report = Get-ChannelForgeCategoryReport -CandidateDirectory ([string]$Candidate.CandidateDirectory) -RepositoryRoot $RepositoryRoot
$lines = @(Get-ChannelForgeCategorySummaryLines -Report $report | Where-Object { $_ -and $_ -notlike '## *' })
$suspect = @($report.Rows | Where-Object { $_.Decision -ceq 'conflict' -or $_.Confidence -ceq 'medium' }).Count
$status = if ($suspect -gt 0) { 'attention' } else { 'ok' }
$headline = if ($suspect -gt 0) { "$suspect channels may be in the wrong category. $accept" } else { 'Channels are sorted into categories. Looks fine.' }
[void]$checks.Add([pscustomobject][ordered]@{ Kind = 'categories'; Status = $status; Headline = $headline; Details = $lines })
}
catch {
[void]$checks.Add([pscustomobject][ordered]@{ Kind = 'categories'; Status = 'unavailable'; Headline = 'Category check could not run. You can still accept.'; Details = @() })
}
return @($checks)
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function Get-ChannelForgeGuidedSetupProposalResponse {
if ($guideOnly -gt 0) { [void]$warnings.Add([pscustomobject][ordered]@{ Code = 'guide-only-record'; Message = 'The guide contains records not present in the playlist.' }) }
if ($unboundGuideCount -gt 0) { [void]$warnings.Add([pscustomobject][ordered]@{ Code = 'guide-unbound-actionable'; Message = 'The guide remains enrolled for later review and will not be applied until explicitly bound.' }) }
if ($candidate.LogoReport.Warning) { [void]$warnings.Add([pscustomobject][ordered]@{ Code = 'logo-check'; Message = [string]$candidate.LogoReport.Warning }) }
$checks = @(Get-ChannelForgeGuidedSetupChecks -Candidate $candidate -RepositoryRoot $RepositoryRoot)
$current = Get-ChannelForgeWebCurrentAcceptedSnapshot -RepositoryRoot $RepositoryRoot
$parentManifestHash = if ($null -eq $current) { $null } else { [string]$current.Manifest.Object.GenerationManifestHash }
$parentStateHash = if ($null -eq $current) { $null } else { [string]$current.State.Object.AcceptedStateHash }
Expand Down Expand Up @@ -292,6 +293,7 @@ function Get-ChannelForgeGuidedSetupProposalResponse {
BlockingReasons = @($blockingReasons)
}
Warnings = @($warnings | Sort-Object Code)
Checks = @($checks)
Safety = [ordered]@{
PublicationState = 'CandidateOnly'
AcceptedStateMutation = 'none'
Expand Down
66 changes: 66 additions & 0 deletions tests/unit/GuidedSetupChecks.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
BeforeAll {
$script:RepoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
Import-Module (Join-Path $script:RepoRoot 'src\ChannelForge\ChannelForge.psd1') -Force

function Get-TestChecksProposal {
param([Parameter(Mandatory)][string]$Root, [Parameter(Mandatory)][string]$Playlist)
$rules = Join-Path $Root 'data\rules'
$lineup = Join-Path $Root 'data\lineup'
New-Item -ItemType Directory -Force -Path $rules, $lineup | Out-Null
Copy-Item -LiteralPath (Join-Path $script:RepoRoot 'data\rules\aliases.json') -Destination $rules
Copy-Item -LiteralPath (Join-Path $script:RepoRoot 'data\lineup\numbering_blocks.json') -Destination $lineup
$item = [ordered]@{ sourceKey = 'p1'; label = 'p1'; priority = 100; contentBase64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($Playlist)) }
$payload = [ordered]@{ schemaVersion = 2; playlists = @([pscustomobject]$item); guides = @(); bindings = @() }
$body = [Text.Encoding]::UTF8.GetBytes(($payload | ConvertTo-Json -Depth 10 -Compress))
$response = & (Get-Module ChannelForge) {
param($RequestRoot, $RequestBody)
Get-ChannelForgeWebResponse -Method POST -Path '/api/guided-setup/proposal' -RepositoryRoot $RequestRoot -StaticRoot '' -BodyBytes $RequestBody -ContentType 'application/json' -ContentLength $RequestBody.Length
} $Root $body
$response.StatusCode | Should -Be 200
return ($response.Body | ConvertFrom-Json)
}
}

Describe 'Guided setup checks before accepting' {
BeforeAll {
$script:NoLogo = "#EXTM3U`n#EXTINF:-1 tvg-id=one,One`nhttps://example.invalid/one`n"
}

It 'shows a logo check that needs attention for a channel with no logo' {
$payload = Get-TestChecksProposal -Root (Join-Path $TestDrive 'logo') -Playlist $script:NoLogo
$logos = @($payload.Checks | Where-Object { $_.Kind -eq 'logos' })
$logos.Count | Should -Be 1
$logos[0].Status | Should -Be 'attention'
$logos[0].Headline | Should -Not -Match 'Set-ChannelForge'
$payload.Proposal.CanAccept | Should -BeTrue
@($payload.Checks | Where-Object { $_.Kind -eq 'categories' })[0].Status | Should -BeIn 'ok', 'attention'
}

It 'still returns a ready proposal when the category report fails' {
Mock -ModuleName ChannelForge Get-ChannelForgeCategoryReport { throw 'C:\secret\place failed' }
$payload = Get-TestChecksProposal -Root (Join-Path $TestDrive 'cat-fail') -Playlist $script:NoLogo
$payload.Status | Should -Be 'PROPOSAL_READY'
$payload.Proposal.CanAccept | Should -BeTrue
$categories = @($payload.Checks | Where-Object { $_.Kind -eq 'categories' })
$categories[0].Status | Should -Be 'unavailable'
$categories[0].Headline | Should -Be 'Category check could not run. You can still accept.'
($categories[0] | ConvertTo-Json -Depth 5) | Should -Not -Match 'secret'
}

It 'keeps the candidate hash and accept state the same and names no staging path' {
$rootA = Join-Path $TestDrive 'same-a'
$rootB = Join-Path $TestDrive 'same-b'
$a = Get-TestChecksProposal -Root $rootA -Playlist $script:NoLogo
Mock -ModuleName ChannelForge Get-ChannelForgeGuidedSetupChecks { @() }
$b = Get-TestChecksProposal -Root $rootB -Playlist $script:NoLogo
$hashOf = {
param($Root, $Payload)
(Get-Content -Raw -LiteralPath (Join-Path $Root "output\.web-guided-setup\proposals\$($Payload.Proposal.ProposalId)\session.json") | ConvertFrom-Json).CandidateManifestHash
}
(& $hashOf $rootA $a) | Should -Be (& $hashOf $rootB $b)
$a.Proposal.CanAccept | Should -Be $b.Proposal.CanAccept
$text = ($a.Checks | ConvertTo-Json -Depth 6)
$text | Should -Not -Match 'web-guided-setup'
$text | Should -Not -Match ([regex]::Escape($rootA))
}
}
Loading