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
2 changes: 1 addition & 1 deletion gui/src/app/guidedSetupProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
2 changes: 1 addition & 1 deletion gui/src/pages/GuidedSetupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<li>
Expand Down
22 changes: 22 additions & 0 deletions gui/src/test/guided-setup-browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<GuidedSetupSourceSetSubmitter>().mockResolvedValue(withGuides)
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(/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<GuidedSetupSourceSetSubmitter>().mockResolvedValue(readyProposal)
Expand Down
18 changes: 18 additions & 0 deletions src/ChannelForge/Private/Get-ChannelForgeGuidedSetupChecks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ function New-ChannelForgeCandidateProposalFromSourceSet {
CandidateDirectory = $finalPath
Manifest = [pscustomobject]$manifest
LogoReport = $logoReport
GuideProgrammes = @($programmesForOutput.ToArray())
}
}
catch {
Expand Down
48 changes: 46 additions & 2 deletions tests/unit/GuidedSetupChecks.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) "<?xml version=`"1.0`"?><tv><channel id=`"one`"><display-name>One</display-name></channel><programme channel=`"one`" start=`"20300101000000 +0000`" stop=`"20300101010000 +0000`"><title>$title</title></programme></tv>" }
$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 = '<?xml version="1.0"?><tv><channel id="one"><display-name>One</display-name></channel><programme channel="one" start="20300101000000 +0000" stop="20300101010000 +0000"><title>News</title></programme></tv>'
$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 = '<?xml version="1.0"?><tv><channel id="one"><display-name>One</display-name></channel><programme channel="one" start="20300101000000 +0000" stop="20300101010000 +0000"><title>News</title></programme></tv>'
$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'
}
}
Loading