91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdir, mkdtemp, readFile, writeFile } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import {
|
|
buildPhase3TrailNoteImport,
|
|
loadLatestTrailReportArtifact,
|
|
loadLatestTrailReportCreatedEvent,
|
|
persistPhase3NoteOutputs,
|
|
} from './ecosystem-phase3.ts';
|
|
|
|
test('builds and persists a NoteLett audit note from the latest trail report artifact', async () => {
|
|
const root = await mkdtemp(join(tmpdir(), 'notelett-phase3-'));
|
|
await mkdir(join(root, 'indexes'), { recursive: true });
|
|
await writeFile(
|
|
join(root, 'indexes', 'latest-trail-report.json'),
|
|
`${JSON.stringify({
|
|
id: 'art_trail_demo',
|
|
title: 'Cowork audit report for task task_phase3_demo',
|
|
summary: '3 audited actions, 1 safety signal',
|
|
ownership: { userId: 'saravana', orgId: null },
|
|
provenance: {
|
|
sessionId: 'sess_phase3',
|
|
correlationId: 'corr_phase3',
|
|
lineage: [
|
|
{
|
|
stepType: 'trail-report-created',
|
|
productId: 'actiontrail',
|
|
actorType: 'agent',
|
|
timestamp: '2026-04-03T14:05:00.000Z',
|
|
},
|
|
],
|
|
},
|
|
payload: {
|
|
sourceProduct: 'claw-cowork',
|
|
sourceTaskId: 'task_phase3_demo',
|
|
reportGeneratedAt: '2026-04-03T14:05:00.000Z',
|
|
actionCount: 3,
|
|
toolCallCount: 1,
|
|
approvalCount: 1,
|
|
failureCount: 0,
|
|
safetySignalCount: 1,
|
|
actionBreakdown: [
|
|
{ action: 'ToolCall', count: 1 },
|
|
{ action: 'InjectionDetected', count: 1 },
|
|
],
|
|
entries: [
|
|
{
|
|
timestamp: '2026-04-03T14:01:00.000Z',
|
|
taskId: 'task_phase3_demo',
|
|
action: 'ToolCall',
|
|
tool: 'search_query',
|
|
inputSummary: 'Find roadmap delta',
|
|
result: 'Success',
|
|
},
|
|
],
|
|
},
|
|
}, null, 2)}\n`,
|
|
'utf-8'
|
|
);
|
|
await writeFile(
|
|
join(root, 'indexes', 'latest-trail-report-created-event.json'),
|
|
`${JSON.stringify({ eventId: 'evt_trail_created_demo', eventName: 'artifact.created', trace: { correlationId: 'corr_phase3', causationId: 'task_phase3_demo', parentEventId: 'task_phase3_demo' } }, null, 2)}\n`,
|
|
'utf-8'
|
|
);
|
|
|
|
const trailReportArtifact = await loadLatestTrailReportArtifact(root);
|
|
const trailReportCreatedEvent = await loadLatestTrailReportCreatedEvent(root);
|
|
const generated = buildPhase3TrailNoteImport({
|
|
trailReportArtifact,
|
|
trailReportCreatedEvent,
|
|
workspaceId: 'ws_phase3',
|
|
userId: 'saravana',
|
|
root,
|
|
now: '2026-04-03T14:10:00.000Z',
|
|
});
|
|
|
|
assert.equal(generated.note.sourceType, 'ecosystem-trail-report');
|
|
assert.equal(generated.createdEvent.trace.causationId, 'evt_trail_created_demo');
|
|
assert.equal(generated.linkedEvent.payload.relation, 'summarizes');
|
|
|
|
await persistPhase3NoteOutputs({ ...generated, root });
|
|
|
|
const linkedEvent = JSON.parse(
|
|
await readFile(join(root, 'indexes', 'latest-note-linked-event.json'), 'utf-8')
|
|
) as { payload: { targetArtifactId: string } };
|
|
|
|
assert.equal(linkedEvent.payload.targetArtifactId, 'art_trail_demo');
|
|
});
|