From 40c248d3265e1817426af1e74d6af89aa6e6f079 Mon Sep 17 00:00:00 2001 From: Jumpstile Date: Tue, 17 Nov 2026 09:20:44 -0500 Subject: [PATCH] Keep channels with programmes out of the missing group when the tvg-id has spaces or symbols (#191) The evidence builder only accepts plain ids, so real tvg-ids with spaces or symbols fell back to a no-reference record and showed as missing even when the guide had programmes for them. The mapper now gives such an id a stable reference made from a hash of the id (existing domain hash helper); programmes are still looked up by the original id. Empty ids are unchanged. The builder and every contract are untouched. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01NzHAcjThVoUGWWfXrYWsNh --- ...-ChannelForgeGuideEvidenceFromPlaylist.ps1 | 12 ++++++----- .../unit/GuideEvidenceFromPlaylist.Tests.ps1 | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ChannelForge/Private/ConvertTo-ChannelForgeGuideEvidenceFromPlaylist.ps1 b/src/ChannelForge/Private/ConvertTo-ChannelForgeGuideEvidenceFromPlaylist.ps1 index 04f5302..73483df 100644 --- a/src/ChannelForge/Private/ConvertTo-ChannelForgeGuideEvidenceFromPlaylist.ps1 +++ b/src/ChannelForge/Private/ConvertTo-ChannelForgeGuideEvidenceFromPlaylist.ps1 @@ -8,7 +8,7 @@ function ConvertTo-ChannelForgeGuideEvidenceFromPlaylist { - Channel has programmes: XMLTV evidence. StartUtc/EndUtc is the span the guide covers for that channel. The guide is Stale when that span ended before BuildTimeUtc, else Current. State is SafeCandidate: one source, never cross-checked. Source relationship stays Unknown. - - Channel has no programmes (or no usable tvg-id): ProviderM3UMetadata evidence, Unresolved, reasons + - Channel has no programmes (or no tvg-id): ProviderM3UMetadata evidence, Unresolved, reasons EvidenceMissing and NoEventData. It is never dropped. - Title is the channel display name, so each channel is one readiness group. Programme titles are not used. Channels are sorted first, so the result does not depend on input order. @@ -39,12 +39,14 @@ function ConvertTo-ChannelForgeGuideEvidenceFromPlaylist { $ordered = @($Channel | Where-Object { $null -ne $_ } | Sort-Object { [string]$_.TvgId }, { [string]$_.DisplayName }) foreach ($c in $ordered) { $tvgId = [string]$c.TvgId - $usable = $tvgId -cmatch '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$' + $hasId = -not [string]::IsNullOrEmpty($tvgId) + $reference = if ($tvgId -cmatch '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$') { $tvgId } + elseif ($hasId) { 'id-' + (Get-ChannelForgeDomainHash -Domain 'channelforge/guide-id/v1' -Bytes ([System.Text.UTF8Encoding]::new($false).GetBytes($tvgId))).Substring(0, 32) } $name = [string]$c.DisplayName $common = @{ SourceId = $SourceId; DisplayName = $name; Group = [string]$c.Group } - if ($usable) { $common.ChannelReference = $tvgId; $common.Title = $name } + if ($hasId) { $common.ChannelReference = $reference; $common.Title = $name } - if ($usable -and $span.ContainsKey($tvgId)) { + if ($hasId -and $span.ContainsKey($tvgId)) { $s = $span[$tvgId] New-ChannelForgeGuideEvidence -EvidenceType XMLTV @common ` -StartUtc $s.Start.UtcDateTime.ToString($format, $culture) -EndUtc $s.End.UtcDateTime.ToString($format, $culture) ` @@ -52,7 +54,7 @@ function ConvertTo-ChannelForgeGuideEvidenceFromPlaylist { -FreshnessState $(if ($s.End.UtcDateTime -lt $build) { 'Stale' } else { 'Current' }) } else { - $codes = if ($span.ContainsKey($tvgId)) { @('InvalidGuideId') } else { @('EvidenceMissing', 'NoEventData') } + $codes = @('EvidenceMissing', 'NoEventData') New-ChannelForgeGuideEvidence -EvidenceType ProviderM3UMetadata @common -ReasonCodes $codes } } diff --git a/tests/unit/GuideEvidenceFromPlaylist.Tests.ps1 b/tests/unit/GuideEvidenceFromPlaylist.Tests.ps1 index f452d2d..bece8d6 100644 --- a/tests/unit/GuideEvidenceFromPlaylist.Tests.ps1 +++ b/tests/unit/GuideEvidenceFromPlaylist.Tests.ps1 @@ -51,3 +51,24 @@ Describe 'Guide evidence from a playlist and one guide' { ($two.Readiness | ConvertTo-Json -Depth 8) | Should -Be ($one.Readiness | ConvertTo-Json -Depth 8) } } + +Describe 'Guide evidence for tvg-ids with spaces and symbols' { + BeforeAll { + $script:Odd = @((New-Chan 'BBC One (HD) | UK' 'One'), (New-Chan 'BBC One (HD) & UK' 'Two'), (New-Chan 'No Guide #1' 'Three')) + $script:OddProg = @((New-Prog 'BBC One (HD) | UK' '2026-10-01T10:00:00Z'), (New-Prog 'BBC One (HD) & UK' '2026-10-01T10:00:00Z')) + } + + It 'counts a channel with programmes as guided, not missing, and keeps two odd ids apart' { + $r = Get-Ready $script:Odd $script:OddProg + @($r.Readiness.Records).Count | Should -Be 3 + $r.Readiness.StateCounts.SafeCandidate | Should -Be 2 + $r.Readiness.StateCounts.Unresolved | Should -Be 1 + @($r.Evidence.ChannelReference | Where-Object { $_ } | Select-Object -Unique).Count | Should -Be 3 + } + + It 'gives the same result whatever the channel order' { + $one = Get-Ready $script:Odd $script:OddProg + $two = Get-Ready @($script:Odd[2..0]) @($script:OddProg[1..0]) + ($two.Readiness | ConvertTo-Json -Depth 8) | Should -Be ($one.Readiness | ConvertTo-Json -Depth 8) + } +}