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