diff --git a/gui/src/app/guidedSetupProposal.ts b/gui/src/app/guidedSetupProposal.ts index baee40d..165c098 100644 --- a/gui/src/app/guidedSetupProposal.ts +++ b/gui/src/app/guidedSetupProposal.ts @@ -4,7 +4,7 @@ export const proposalRequestLimits = { } as const export type GuidedSetupCheck = { - Kind: 'logos' | 'categories' + Kind: 'logos' | 'categories' | 'guides' Status: 'ok' | 'attention' | 'unavailable' Headline: string Details: string[] diff --git a/gui/src/pages/GuidedSetupPage.tsx b/gui/src/pages/GuidedSetupPage.tsx index 6bbc926..98288a4 100644 --- a/gui/src/pages/GuidedSetupPage.tsx +++ b/gui/src/pages/GuidedSetupPage.tsx @@ -109,7 +109,7 @@ type GuideBindingSelection = { function ProposalCheckRow({ check }: { check: GuidedSetupCheck }) { const [open, setOpen] = useState(false) - const name = check.Kind === 'logos' ? 'Logos' : 'Categories' + const name = check.Kind === 'logos' ? 'Logos' : check.Kind === 'guides' ? 'Guides' : 'Categories' const state = check.Status === 'ok' ? 'OK' : check.Status === 'attention' ? 'Needs a look' : 'Not available' return (
  • diff --git a/gui/src/test/guided-setup-browser.test.tsx b/gui/src/test/guided-setup-browser.test.tsx index 1aa187d..a3b9579 100644 --- a/gui/src/test/guided-setup-browser.test.tsx +++ b/gui/src/test/guided-setup-browser.test.tsx @@ -73,6 +73,28 @@ describe('browser Guided Setup proposal and acceptance', () => { expect(screen.getByRole('button', { name: 'Accept reviewed proposal' })).toBeDisabled() }) + it('shows the guide check headline, hides its details until asked, and still needs the acknowledgement', async () => { + const user = userEvent.setup() + const withGuides: GuidedSetupSourceSetProposal = { + ...readyProposal, + Checks: [ + { Kind: 'guides', Status: 'attention', Headline: 'Your guides disagree on 1 programmes. You can accept, or fix this first (see Details).', Details: ['channel one: 2030-01-01 00:00 is "A" in g1, "B" in g2'] }, + ], + } + const submitter = vi.fn().mockResolvedValue(withGuides) + 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(/Your guides disagree on 1 programmes/)).toBeInTheDocument() + expect(screen.queryByText(/is "A" in g1/)).not.toBeInTheDocument() + await user.click(screen.getByRole('button', { name: 'Details' })) + expect(screen.getByText(/is "A" in g1/)).toBeInTheDocument() + expect(screen.getByRole('button', { name: 'Accept reviewed proposal' })).toBeDisabled() + await user.click(screen.getByLabelText(/I reviewed these results/)) + expect(screen.getByRole('button', { name: 'Accept reviewed proposal' })).toBeEnabled() + }) + 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 index fa257ad..8710007 100644 --- a/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupChecks.ps1 +++ b/src/ChannelForge/Private/Get-ChannelForgeGuidedSetupChecks.ps1 @@ -36,5 +36,23 @@ function Get-ChannelForgeGuidedSetupChecks { catch { [void]$checks.Add([pscustomobject][ordered]@{ Kind = 'categories'; Status = 'unavailable'; Headline = 'Category check could not run. You can still accept.'; Details = @() }) } + $programmes = @($Candidate.GuideProgrammes) + if (@($programmes | ForEach-Object { [string]$_.SourceId } | Sort-Object -Unique).Count -ge 2) { + try { + $xguide = @(Get-ChannelForgeXguideReport -Programme $programmes -BuildTimeUtc ([datetime]::UtcNow))[-1] + $guideLines = @(Get-ChannelForgeXguideSummaryLines -Report $xguide | Where-Object { $_ -and $_ -notlike '## *' }) + $behind = [int]$xguide.Counts.GuideBehind + $differences = (@($xguide.Counts.PSObject.Properties | ForEach-Object { [int]$_.Value } | Measure-Object -Sum).Sum) - $behind + $guideStatus = if ($differences + $behind -gt 0) { 'attention' } else { 'ok' } + $guideHeadline = if ($differences -gt 0) { "Your guides disagree on $differences shows. $accept" } + elseif ($behind -gt 0) { "A guide looks empty, ended or out of date. $accept" } + elseif ($xguide.SharedChannelCount -eq 0) { 'Your guides share no channels, so there is nothing to compare.' } + else { 'Your guides agree on their shared channels. Looks fine.' } + [void]$checks.Add([pscustomobject][ordered]@{ Kind = 'guides'; Status = $guideStatus; Headline = $guideHeadline; Details = $guideLines }) + } + catch { + [void]$checks.Add([pscustomobject][ordered]@{ Kind = 'guides'; Status = 'unavailable'; Headline = 'Guide check could not run. You can still accept.'; Details = @() }) + } + } return @($checks) } diff --git a/src/ChannelForge/Private/New-ChannelForgeCandidateProposalFromSourceSet.ps1 b/src/ChannelForge/Private/New-ChannelForgeCandidateProposalFromSourceSet.ps1 index 3d396e4..11a3d37 100644 --- a/src/ChannelForge/Private/New-ChannelForgeCandidateProposalFromSourceSet.ps1 +++ b/src/ChannelForge/Private/New-ChannelForgeCandidateProposalFromSourceSet.ps1 @@ -343,6 +343,7 @@ function New-ChannelForgeCandidateProposalFromSourceSet { CandidateDirectory = $finalPath Manifest = [pscustomobject]$manifest LogoReport = $logoReport + GuideProgrammes = @($programmesForOutput.ToArray()) } } catch { diff --git a/tests/unit/GuidedSetupChecks.Tests.ps1 b/tests/unit/GuidedSetupChecks.Tests.ps1 index 4a42d25..9a75b13 100644 --- a/tests/unit/GuidedSetupChecks.Tests.ps1 +++ b/tests/unit/GuidedSetupChecks.Tests.ps1 @@ -3,14 +3,14 @@ BeforeAll { Import-Module (Join-Path $script:RepoRoot 'src\ChannelForge\ChannelForge.psd1') -Force function Get-TestChecksProposal { - param([Parameter(Mandatory)][string]$Root, [Parameter(Mandatory)][string]$Playlist) + param([Parameter(Mandatory)][string]$Root, [Parameter(Mandatory)][string]$Playlist, [string[]]$Guides = @()) $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 = @() } + $payload = [ordered]@{ schemaVersion = 2; playlists = @([pscustomobject]$item); guides = @($Guides | ForEach-Object -Begin { $n = 0 } -Process { $n++; [pscustomobject][ordered]@{ sourceKey = "g$n"; label = "g$n"; priority = 100; contentBase64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($_)) } }); bindings = @(1..@($Guides).Count | Where-Object { $Guides } | ForEach-Object { [pscustomobject][ordered]@{ guideRef = "g$_"; playlistRefs = @(); appliesToAll = $true } }) } $body = [Text.Encoding]::UTF8.GetBytes(($payload | ConvertTo-Json -Depth 10 -Compress)) $response = & (Get-Module ChannelForge) { param($RequestRoot, $RequestBody) @@ -63,4 +63,48 @@ Describe 'Guided setup checks before accepting' { $text | Should -Not -Match 'web-guided-setup' $text | Should -Not -Match ([regex]::Escape($rootA)) } + + It 'warns in plain words when two guides disagree about the same channel, and changes nothing else' { + $guide = { param($title) "One$title" } + $guides = @((& $guide 'Evening News'), (& $guide 'Cooking Show')) + $rootA = Join-Path $TestDrive 'guides-a' + $rootB = Join-Path $TestDrive 'guides-b' + $a = Get-TestChecksProposal -Root $rootA -Playlist $script:NoLogo -Guides $guides + $row = @($a.Checks | Where-Object { $_.Kind -eq 'guides' }) + $row.Count | Should -Be 1 + $row[0].Status | Should -Be 'attention' + $row[0].Headline | Should -Match 'disagree' + ($row[0].Details -join "`n") | Should -Match 'Cooking Show' + $a.Proposal.CanAccept | Should -BeTrue + $text = ($a.Checks | ConvertTo-Json -Depth 6) + $text | Should -Not -Match 'web-guided-setup' + $text | Should -Not -Match ([regex]::Escape($rootA)) + Mock -ModuleName ChannelForge Get-ChannelForgeGuidedSetupChecks { @() } + $b = Get-TestChecksProposal -Root $rootB -Playlist $script:NoLogo -Guides $guides + $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 + (Get-Content -Raw -LiteralPath (Join-Path $rootA "output\.web-guided-setup\proposals\$($a.Proposal.ProposalId)\session.json")) | Should -Not -Match 'Cooking Show' + } + + It 'shows no guide check for a single guide' { + $guide = 'OneNews' + $payload = Get-TestChecksProposal -Root (Join-Path $TestDrive 'one-guide') -Playlist $script:NoLogo -Guides @($guide) + @($payload.Checks | Where-Object { $_.Kind -eq 'guides' }).Count | Should -Be 0 + } + + It 'still returns a ready proposal when the guide comparison fails' { + Mock -ModuleName ChannelForge Get-ChannelForgeXguideReport { throw 'C:\secret\place failed' } + $guide = 'OneNews' + $payload = Get-TestChecksProposal -Root (Join-Path $TestDrive 'guide-fail') -Playlist $script:NoLogo -Guides @($guide, $guide) + $payload.Status | Should -Be 'PROPOSAL_READY' + $payload.Proposal.CanAccept | Should -BeTrue + $row = @($payload.Checks | Where-Object { $_.Kind -eq 'guides' }) + $row[0].Status | Should -Be 'unavailable' + $row[0].Headline | Should -Be 'Guide check could not run. You can still accept.' + ($row[0] | ConvertTo-Json -Depth 5) | Should -Not -Match 'secret' + } }