Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { buildReport, parseLedger } from '#/lib/completeness.ts'
3import {
4 parseSourceSilentEvidence,
5 withSourceSilentEvidence,
6} from './source-silent-facts.ts'
7
8const row = {
9 providerId: 'synthetic',
10 activity: 'chat',
11 contextWindow: null,
12 maxOutput: null,
13 modalities: null,
14 pricing: null,
15 capabilities: null,
16 reasoning: null,
17 requestMap: null,
18}
19const ledger = parseSourceSilentEvidence(
20 '- synthetic: maxOutput — absent, https://example.com/docs, checked 2026-10-09\n- synthetic: capabilities — absent, https://example.com/docs, checked 2026-10-09',
21)
22
23describe('source-silent API evidence', () => {
24 it('copies recorded metadata and leaves absent metadata absent', () => {
25 expect(ledger.get('synthetic')?.get('maxOutput')).toEqual({
26 derivation: 'source-silent',
27 sourceUrl: 'https://example.com/docs',
28 checkedAt: '2026-10-09',
29 })
30 expect(
31 parseSourceSilentEvidence('- synthetic: maxOutput — absent')
32 .get('synthetic')
33 ?.get('maxOutput'),
34 ).toEqual({ derivation: 'source-silent' })
35 })
36 it('rejects typo facts and duplicate evidence instead of choosing an arbitrary source', () => {
37 expect(() =>
38 parseSourceSilentEvidence('- synthetic: maxOutputs — absent'),
39 ).toThrow(/unknown fact/)
40 expect(() =>
41 parseSourceSilentEvidence(
42 '- synthetic: maxOutput — absent\n- synthetic: maxOutput — absent',
43 ),
44 ).toThrow(/duplicate/)
45 })
46 it('rejects malformed recorded dates instead of dropping or normalizing them', () => {
47 for (const date of ['2026-02-30', '2026-13-01', '2026-1-09', 'unknown']) {
48 expect(() =>
49 parseSourceSilentEvidence(
50 `- synthetic: maxOutput — absent, checked ${date}`,
51 ),
52 ).toThrow(/invalid checked date/)
53 }
54 })
55 it('adds evidence only for ledgered null facts, with whole-field capability silence', () => {
56 const sources = withSourceSilentEvidence(row, null, null, ledger)
57 expect(sources?.maxOutput?.derivation).toBe('source-silent')
58 expect(sources?.capabilities).toEqual(
59 ledger.get('synthetic')?.get('capabilities'),
60 )
61 expect(sources).not.toHaveProperty('contextWindow')
62 expect(
63 withSourceSilentEvidence(
64 { ...row, providerId: 'unledgered' },
65 null,
66 null,
67 ledger,
68 ),
69 ).toBeNull()
70 })
71 it('preserves populated facts and sameAs evidence without mutating stored sources', () => {
72 const stored = {
73 maxOutput: {
74 derivation: 'listing' as const,
75 sourceUrl: 'https://example.com/list',
76 },
77 capabilities: { tools: { derivation: 'listing' as const } },
78 sameAs: { derivation: 'listing' as const, normalized: true as const },
79 schemaEndpointId: {
80 derivation: 'docs-derived' as const,
81 sourceUrl: 'https://example.com/routes',
82 },
83 }
84 expect(
85 withSourceSilentEvidence(
86 { ...row, maxOutput: 1024, capabilities: { tools: true } },
87 null,
88 stored,
89 ledger,
90 ),
91 ).toEqual(stored)
92 const missing = withSourceSilentEvidence(row, null, stored, ledger)
93 expect(missing?.sameAs).toEqual(stored.sameAs)
94 expect(missing?.schemaEndpointId).toEqual(stored.schemaEndpointId)
95 expect(stored.maxOutput.derivation).toBe('listing')
96 })
97 it('keeps evidence for missing subfacts separate from populated parent provenance', () => {
98 const subfacts = parseSourceSilentEvidence(
99 '- synthetic: priced — absent\n- synthetic: cacheRead — absent\n- synthetic: efforts — absent\n- synthetic: endpoint — absent\n- synthetic: requestMap — absent',
100 )
101 const stored = {
102 pricing: { derivation: 'listing' as const },
103 reasoning: { derivation: 'listing' as const },
104 }
105 const model = {
106 ...row,
107 pricing: {
108 tables: { rate: { base: { input_tokens: 1, output_tokens: 2 } } },
109 },
110 reasoning: { mode: 'effort', mandatory: null },
111 requestMap: { replayReasoningContent: null },
112 }
113 const sources = withSourceSilentEvidence(model, null, stored, subfacts)
114 expect(sources).toMatchObject({
115 ...stored,
116 cacheRead: { derivation: 'source-silent' },
117 efforts: { derivation: 'source-silent' },
118 schemaEndpointId: { derivation: 'source-silent' },
119 })
120 expect(sources).not.toHaveProperty('requestMap')
121 expect(
122 withSourceSilentEvidence(
123 model,
124 null,
125 {
126 ...stored,
127 cacheRead: { derivation: 'docs-derived', path: 'not-offered' },
128 },
129 subfacts,
130 )?.cacheRead,
131 ).toEqual({ derivation: 'docs-derived', path: 'not-offered' })
132 expect(
133 withSourceSilentEvidence(
134 {
135 ...model,
136 pricing: { tables: { rate: { base: { cache_read_tokens: 0 } } } },
137 reasoning: { mode: 'effort', efforts: ['low'] },
138 },
139 '/v1/chat',
140 stored,
141 subfacts,
142 ),
143 ).toEqual(stored)
144 })
145 it('does not apply chat ledger evidence to unrelated activities', () => {
146 expect(
147 withSourceSilentEvidence(
148 { ...row, activity: 'image' },
149 null,
150 null,
151 ledger,
152 ),
153 ).toBeNull()
154 })
155})
156
157describe('model-scoped replay silence evidence', () => {
158 const scoped = parseSourceSilentEvidence(
159 '- synthetic/maker/model: replayReasoningContent — absent, https://example.com/model, checked 2026-10-09\n- synthetic/maker/model: maxOutput — absent',
160 )
161 it('adds only exact native-model leaf evidence without inventing a value or parent source', () => {
162 const model = {
163 ...row,
164 rawId: 'maker/model',
165 requestMap: {
166 maxTokensField: 'max_tokens',
167 replayReasoningContent: null,
168 },
169 }
170 const source = {
171 derivation: 'docs-derived' as const,
172 sourceUrl: 'https://example.com/body',
173 }
174 const stored = {
175 requestMap: source,
176 requestMapFields: { maxTokensField: source },
177 sameAs: { derivation: 'listing' as const },
178 }
179 expect(withSourceSilentEvidence(model, null, stored, scoped)).toMatchObject(
180 {
181 requestMap: source,
182 requestMapFields: {
183 maxTokensField: source,
184 replayReasoningContent: {
185 derivation: 'source-silent',
186 sourceUrl: 'https://example.com/model',
187 checkedAt: '2026-10-09',
188 },
189 },
190 sameAs: stored.sameAs,
191 maxOutput: { derivation: 'source-silent' },
192 },
193 )
194 expect(model.requestMap.replayReasoningContent).toBeNull()
195 expect(stored.requestMapFields).not.toHaveProperty('replayReasoningContent')
196 expect(
197 withSourceSilentEvidence(
198 { ...model, rawId: 'maker/model-snapshot' },
199 null,
200 stored,
201 scoped,
202 ),
203 ).toEqual(stored)
204 })
205 it('preserves true and false replay facts and their original provenance', () => {
206 const source = {
207 derivation: 'docs-derived' as const,
208 sourceUrl: 'https://example.com/known',
209 }
210 const stored = { requestMapFields: { replayReasoningContent: source } }
211 for (const replayReasoningContent of [true, false]) {
212 const result = withSourceSilentEvidence(
213 {
214 ...row,
215 rawId: 'maker/model',
216 maxOutput: 1,
217 requestMap: { replayReasoningContent },
218 },
219 null,
220 stored,
221 scoped,
222 )
223 expect(result).toEqual(stored)
224 }
225 })
226 it('adds leaf evidence for missing request maps without fabricating a request map', () => {
227 const model = { ...row, rawId: 'maker/model' }
228 expect(
229 withSourceSilentEvidence(model, null, null, scoped)?.requestMapFields
230 ?.replayReasoningContent?.derivation,
231 ).toBe('source-silent')
232 expect(model.requestMap).toBeNull()
233 expect(
234 withSourceSilentEvidence(model, null, null, scoped),
235 ).not.toHaveProperty('requestMap')
236 })
237 it('serves a serverTools entry on a null row only, never scoring it (#707)', () => {
238 const markdown =
239 '- `synthetic/m-1`: serverTools — no model page, https://example.com/m, checked 2026-11-21'
240 const tools = parseSourceSilentEvidence(markdown)
241 const silent = {
242 derivation: 'source-silent',
243 sourceUrl: 'https://example.com/m',
244 checkedAt: '2026-11-21',
245 }
246 const m1 = { ...row, rawId: 'm-1', serverTools: null }
247 expect(withSourceSilentEvidence(m1, null, null, tools)).toEqual({
248 serverTools: silent,
249 })
250 expect(
251 withSourceSilentEvidence(
252 { ...m1, serverTools: ['mcp'] },
253 null,
254 null,
255 tools,
256 ),
257 ).toBeNull()
258 // A poll-time silence from the model's own page stays as stored.
259 const stored = {
260 serverTools: {
261 derivation: 'source-silent' as const,
262 sourceUrl: 'https://example.com/page',
263 },
264 }
265 expect(withSourceSilentEvidence(m1, null, stored, tools)).toEqual(stored)
266 // Evidence only: the entry changes no score.
267 const rows = [{ provider: 'synthetic', rawId: 'm-1', activity: 'chat' }]
268 expect(buildReport(rows, parseLedger(markdown)).providers).toEqual(
269 buildReport(rows).providers,
270 )
271 })
272})