Skip to content

Commit e77052a

Browse files
authored
test(ai): add contentTrust reader regression (#13703) (#13704)
1 parent 2137d89 commit e77052a

2 files changed

Lines changed: 76 additions & 11 deletions

File tree

test/playwright/unit/ai/services/ingestion/IssueIngestor.spec.mjs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const __filename = fileURLToPath(import.meta.url);
1818
const __dirname = path.dirname(__filename);
1919
const repoRoot = path.resolve(__dirname, '../../../../../../..');
2020

21+
const RAW_EXTERNAL_URL = 'https://arkforge.tech/payload';
22+
const QUARANTINED_URL = '[QUARANTINED_URL: arkforge.tech]';
23+
2124
test.describe('Neo.ai.daemons.services.IssueIngestor', () => {
2225
let IssueIngestor;
2326
let StorageRouter;
@@ -44,9 +47,21 @@ test.describe('Neo.ai.daemons.services.IssueIngestor', () => {
4447
];
4548

4649
const mockFiles = {
47-
'resources/content/issues/issue-2001.md': '---\nstate: OPEN\n---\n# Active Issue',
50+
'resources/content/issues/issue-2001.md': [
51+
'---',
52+
'id: 2001',
53+
'title: Active Issue',
54+
'state: OPEN',
55+
'contentTrust:',
56+
' projected: true',
57+
' quarantined: 1',
58+
'---',
59+
'# Active Issue',
60+
'',
61+
`External source was defanged as ${QUARANTINED_URL}.`
62+
].join('\n'),
4863
'resources/content/archive/issues/v1.0.0/issue-2002.md': '---\nstate: CLOSED\n---\n# Archive Issue',
49-
'resources/content/discussions/discussion-3001.md': [
64+
'resources/content/discussions/discussion-3001.md' : [
5065
'---',
5166
'number: 3001',
5267
'title: Open Discussion',
@@ -94,11 +109,11 @@ test.describe('Neo.ai.daemons.services.IssueIngestor', () => {
94109
_originalGraphDb = GraphService.db;
95110
_originalGetGraphCollection = StorageRouter.getGraphCollection;
96111
GraphService.db = {
97-
nodes: { get: () => null },
98-
edges: { items: [] },
112+
nodes : { get: () => null },
113+
edges : { items: [] },
99114
getAdjacentNodes: () => {},
100-
addNode: node => graphNodes.push(node),
101-
updateNode: () => {}
115+
addNode : node => graphNodes.push(node),
116+
updateNode : () => {}
102117
};
103118

104119
_originalExistsSync = fs.existsSync;
@@ -217,8 +232,8 @@ test.describe('Neo.ai.daemons.services.IssueIngestor', () => {
217232
test('ingestIssueStates() maps issues correctly through _index.json', async () => {
218233
StorageRouter.getGraphCollection = async () => ({
219234
upsert: async () => {},
220-
get: async () => ({ ids: [], metadatas: [], documents: [] }),
221-
add: async () => {}
235+
get : async () => ({ ids: [], metadatas: [], documents: [] }),
236+
add : async () => {}
222237
});
223238

224239
try {
@@ -234,12 +249,35 @@ test.describe('Neo.ai.daemons.services.IssueIngestor', () => {
234249
}
235250
});
236251

252+
test('ingestIssueStates() emits sanitized persisted issue content without raw external URLs (#13703)', async () => {
253+
const upserts = [];
254+
255+
StorageRouter.getGraphCollection = async () => ({
256+
upsert: async payload => upserts.push(payload),
257+
get : async () => ({ ids: [], metadatas: [], documents: [] }),
258+
add : async () => {}
259+
});
260+
261+
try {
262+
const result = await IssueIngestor.ingestIssueStates();
263+
const activeIssue = result.find(issue => issue.issueId === 'issue-2001');
264+
const activeUpsert = upserts.find(payload => payload.ids[0] === 'issue-2001');
265+
266+
expect(activeIssue.body).toContain(QUARANTINED_URL);
267+
expect(activeIssue.body).not.toContain(RAW_EXTERNAL_URL);
268+
expect(activeUpsert.documents[0]).toContain(QUARANTINED_URL);
269+
expect(activeUpsert.documents[0]).not.toContain(RAW_EXTERNAL_URL);
270+
} finally {
271+
StorageRouter.getGraphCollection = _originalGetGraphCollection;
272+
}
273+
});
274+
237275
test('ingestDiscussionStates() maps closed frontmatter into graph and vector lifecycle metadata', async () => {
238276
const upserts = [];
239277

240278
StorageRouter.getGraphCollection = async () => ({
241279
upsert: async payload => upserts.push(payload),
242-
get: async () => ({ ids: [], metadatas: [], documents: [] })
280+
get : async () => ({ ids: [], metadatas: [], documents: [] })
243281
});
244282

245283
try {

test/playwright/unit/ai/services/knowledge-base/source/TicketSource.spec.mjs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const __filename = fileURLToPath(import.meta.url);
1818
const __dirname = path.dirname(__filename);
1919
const repoRoot = path.resolve(__dirname, '../../../../../../..');
2020

21+
const RAW_EXTERNAL_URL = 'https://arkforge.tech/payload';
22+
const QUARANTINED_URL = '[QUARANTINED_URL: arkforge.tech]';
23+
2124
test.describe('Neo.ai.services.knowledge-base.source.TicketSource', () => {
2225
let TicketSource;
2326
let aiConfig;
@@ -41,10 +44,22 @@ test.describe('Neo.ai.services.knowledge-base.source.TicketSource', () => {
4144
fs.ensureDirSync(archiveDir);
4245

4346
fs.writeFileSync(path.join(activeDir, 'issue-1001.md'), '# First');
47+
fs.writeFileSync(path.join(activeDir, 'issue-1003.md'), [
48+
'---',
49+
'id: 1003',
50+
'title: Sanitized external issue',
51+
'state: OPEN',
52+
'contentTrust:',
53+
' projected: true',
54+
' quarantined: 1',
55+
'---',
56+
`External source was defanged as ${QUARANTINED_URL}.`
57+
].join('\n'));
4458
fs.writeFileSync(path.join(archiveDir, 'issue-1002.md'), '# Second');
4559

4660
const indexMap = [
4761
{ type: 'issues', id: 1001, path: 'issues/chunk-1/issue-1001.md' },
62+
{ type: 'issues', id: 1003, path: 'issues/chunk-1/issue-1003.md' },
4863
{ type: 'issues', id: 1002, path: 'archive/issues/v1.0.0/chunk-2/issue-1002.md' }
4964
];
5065

@@ -64,9 +79,21 @@ test.describe('Neo.ai.services.knowledge-base.source.TicketSource', () => {
6479

6580
const count = await TicketSource.extract(writeStream, chunk => 'hash');
6681

67-
expect(count).toBe(2);
82+
expect(count).toBe(3);
6883

6984
const ids = written.map(w => w.name).sort();
70-
expect(ids).toEqual(['issue-1001', 'issue-1002']);
85+
expect(ids).toEqual(['issue-1001', 'issue-1002', 'issue-1003']);
86+
});
87+
88+
test('extract() emits persisted contentTrust-sanitized issue content without raw external URLs (#13703)', async () => {
89+
const written = [];
90+
const writeStream = { write(str) { written.push(JSON.parse(str.trim())); return true; } };
91+
92+
await TicketSource.extract(writeStream, chunk => 'hash');
93+
94+
const sanitized = written.find(chunk => chunk.name === 'issue-1003');
95+
96+
expect(sanitized.content).toContain(QUARANTINED_URL);
97+
expect(sanitized.content).not.toContain(RAW_EXTERNAL_URL);
7198
});
7299
});

0 commit comments

Comments
 (0)