diff --git a/gui/src/app/guidedSetupProposal.ts b/gui/src/app/guidedSetupProposal.ts index d87e140..baee40d 100644 --- a/gui/src/app/guidedSetupProposal.ts +++ b/gui/src/app/guidedSetupProposal.ts @@ -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' @@ -79,6 +86,7 @@ export type GuidedSetupSourceSetProposal = { BlockingReasons: string[] } Warnings: Array<{ Code: string; Message: string }> + Checks?: GuidedSetupCheck[] Safety: { PublicationState: 'CandidateOnly' AcceptedStateMutation: 'none' diff --git a/gui/src/pages/GuidedSetupPage.tsx b/gui/src/pages/GuidedSetupPage.tsx index b5c082c..17c4a7f 100644 --- a/gui/src/pages/GuidedSetupPage.tsx +++ b/gui/src/pages/GuidedSetupPage.tsx @@ -3,6 +3,7 @@ import { BookOpen, CheckCircle2, FileText, FolderOpen, ListVideo } from 'lucide- import { acceptGuidedSetupSourceSetProposal, submitGuidedSetupSourceSetProposal, + type GuidedSetupCheck, type GuidedSetupSourceDraft, type GuidedSetupSourceSetAcceptance, type GuidedSetupSourceSetProposal, @@ -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 ( +
  • + {name}: {state}. {check.Headline} + {check.Details.length > 0 ? <> : null} + {open ? : null} +
  • + ) +} + function BrowserGuidedSetupPage({ sourceSetProposalSubmitter, sourceSetAcceptanceSubmitter, @@ -120,6 +134,7 @@ function BrowserGuidedSetupPage({ const [bindings, setBindings] = useState>({}) const [proposal, setProposal] = useState(null) const [accepted, setAccepted] = useState(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(null) const proposalErrorRef = useRef(null) @@ -337,7 +352,8 @@ function BrowserGuidedSetupPage({
    Needs review
    {proposal.Proposal.AmbiguityCount}
    Unbound guides
    {proposal.Proposal.UnboundGuideCount}
    - {proposal.Warnings.length > 0 ?
      {proposal.Warnings.map((warning) =>
    • {warning.Message}
    • )}
    :

    No proposal warnings.

    } + {proposal.Checks && proposal.Checks.length > 0 ? <>

    Checks before you accept

      {proposal.Checks.map((check) => )}
    : null} + {shownWarnings.length > 0 ?
      {shownWarnings.map((warning) =>
    • {warning.Message}
    • )}
    :

    No proposal warnings.

    } {proposal.Proposal.BlockingReasons.length > 0 ?

    Acceptance is blocked until the review blockers are resolved.

    : null} {!accepted ?
    : null} diff --git a/gui/src/test/guided-setup-browser.test.tsx b/gui/src/test/guided-setup-browser.test.tsx index ef382a1..13244ef 100644 --- a/gui/src/test/guided-setup-browser.test.tsx +++ b/gui/src/test/guided-setup-browser.test.tsx @@ -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().mockResolvedValue(withChecks) + render() + 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().mockResolvedValue(readyProposal) diff --git a/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupChecks.ps1 b/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupChecks.ps1 new file mode 100644 index 0000000..fa257ad --- /dev/null +++ b/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupChecks.ps1 @@ -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) +} diff --git a/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupProposal.ps1 b/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupProposal.ps1 index 34a508e..9019711 100644 --- a/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupProposal.ps1 +++ b/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupProposal.ps1 @@ -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 } @@ -292,6 +293,7 @@ function Get-ChannelForgeGuidedSetupProposalResponse { BlockingReasons = @($blockingReasons) } Warnings = @($warnings | Sort-Object Code) + Checks = @($checks) Safety = [ordered]@{ PublicationState = 'CandidateOnly' AcceptedStateMutation = 'none' diff --git a/tests/unit/GuidedSetupChecks.Tests.ps1 b/tests/unit/GuidedSetupChecks.Tests.ps1 new file mode 100644 index 0000000..4a42d25 --- /dev/null +++ b/tests/unit/GuidedSetupChecks.Tests.ps1 @@ -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)) + } +}