Open History to see the last commit
1import { expect, it } from 'vitest'
2import {
3 recordedSources,
4 sourceHref,
5 sourceLinkAlreadyShown,
6} from './provenance.ts'
7
8it('links only recorded absolute HTTP sources without embedded credentials', () => {
9 expect(sourceHref('https://provider.example/docs?q=1')).toBe(
10 'https://provider.example/docs?q=1',
11 )
12 for (const value of [
13 null,
14 '/docs',
15 'javascript:alert(1)',
16 'httpx://provider.example',
17 'https://token@provider.example',
18 ])
19 expect(sourceHref(value)).toBeNull()
20})
21it('preserves leaf association, literal silence evidence and source fingerprints', () => {
22 expect(
23 recordedSources({
24 capabilities: {
25 reasoning: {
26 derivation: 'docs-derived',
27 sourceUrl: 'https://provider.example/reasoning',
28 sourceHash: 'native-hash',
29 path: 'exact native row',
30 },
31 },
32 requestMapFields: {
33 replayReasoningContent: {
34 derivation: 'source-silent',
35 sourceUrl: 'https://provider.example/history',
36 checkedAt: '2026-10-09',
37 },
38 },
39 }),
40 ).toEqual([
41 {
42 field: 'capabilities.reasoning',
43 trace: {},
44 sourceUrl: 'https://provider.example/reasoning',
45 sourceHash: 'native-hash',
46 derivation: 'docs-derived',
47 path: 'exact native row',
48 checkedAt: null,
49 },
50 {
51 field: 'requestMapFields.replayReasoningContent',
52 trace: {},
53 sourceUrl: 'https://provider.example/history',
54 sourceHash: null,
55 derivation: 'source-silent',
56 path: null,
57 checkedAt: '2026-10-09',
58 },
59 ])
60})
61it('does not fill missing sources, borrow a sibling URL, or expose unsafe URLs', () => {
62 expect(recordedSources(null)).toEqual([])
63 expect(
64 recordedSources({
65 contextWindow: { derivation: 'listing' },
66 maxOutput: {
67 derivation: 'docs-derived',
68 sourceUrl: 'javascript:alert(1)',
69 },
70 }).map((x) => x.sourceUrl),
71 ).toEqual([null, null])
72})
73
74it('does not hide a distinct recorded fact source behind a displayed pricing-card link', () => {
75 expect(
76 sourceLinkAlreadyShown(
77 { sourceUrl: 'https://provider.example/prices' },
78 'https://provider.example/prices',
79 ),
80 ).toBe(true)
81 expect(
82 sourceLinkAlreadyShown(
83 { sourceUrl: 'https://provider.example/catalog' },
84 'https://provider.example/prices',
85 ),
86 ).toBe(false)
87 expect(
88 sourceLinkAlreadyShown(
89 { sourceUrl: null },
90 'https://provider.example/prices',
91 ),
92 ).toBe(false)
93 expect(
94 sourceLinkAlreadyShown(
95 { sourceUrl: 'javascript:alert(1)' },
96 'javascript:alert(1)',
97 ),
98 ).toBe(false)
99})
100
101it('preserves literal existing acquisition and verification metadata in the trace', () => {
102 const source = {
103 sourceUrl: 'https://provider.example/spec',
104 fetchedAt: 123,
105 verifiedAt: null,
106 endpointId: 'chat/completions',
107 extractorVersion: 'native-v1',
108 }
109 expect(recordedSources({ schema: source })[0]!.trace).toEqual({
110 fetchedAt: 123,
111 verifiedAt: null,
112 endpointId: 'chat/completions',
113 extractorVersion: 'native-v1',
114 })
115})