1+ import { execFileSync } from "node:child_process" ;
12import fs from "node:fs/promises" ;
23import os from "node:os" ;
34import path from "node:path" ;
4- import { afterEach , describe , expect , it } from "vitest" ;
5+ import { afterEach , describe , expect , it , vi } from "vitest" ;
6+ import { validateQaEvidenceSummaryJson } from "../../../../extensions/qa-lab/api.js" ;
57import {
68 runDiagnosticEventsBoundaryRuntime ,
79 testing ,
@@ -10,20 +12,62 @@ import {
1012const tempDirs : string [ ] = [ ] ;
1113
1214afterEach ( async ( ) => {
15+ vi . unstubAllEnvs ( ) ;
1316 await Promise . all ( tempDirs . splice ( 0 ) . map ( ( dir ) => fs . rm ( dir , { force : true , recursive : true } ) ) ) ;
1417} ) ;
1518
1619describe ( "diagnostic events boundary runtime" , ( ) => {
1720 it ( "composes async dispatch, trusted subscriptions, and model-call trace propagation" , async ( ) => {
1821 const artifactBase = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "diagnostic-events-boundary-" ) ) ;
1922 tempDirs . push ( artifactBase ) ;
23+ const repoRoot = process . cwd ( ) ;
24+ const checkoutSha = execFileSync ( "git" , [ "rev-parse" , "--verify" , "HEAD" ] , {
25+ cwd : repoRoot ,
26+ encoding : "utf8" ,
27+ } ) . trim ( ) ;
28+ vi . stubEnv ( "OPENCLAW_QA_REF" , checkoutSha ) ;
29+ vi . stubEnv ( "OPENCLAW_QA_PACKAGE_SOURCE_KIND" , "source-checkout" ) ;
30+ vi . stubEnv ( "OPENCLAW_QA_PACKAGE_SOURCE_SHA" , checkoutSha ) ;
2031
2132 const { evidence, summary } = await runDiagnosticEventsBoundaryRuntime ( {
2233 artifactBase,
23- repoRoot : process . cwd ( ) ,
34+ repoRoot,
2435 } ) ;
2536
26- expect ( evidence . entries [ 0 ] ?. result . status ) . toBe ( "pass" ) ;
37+ const diskEvidence = validateQaEvidenceSummaryJson (
38+ JSON . parse ( await fs . readFile ( path . join ( artifactBase , "qa-evidence.json" ) , "utf8" ) ) ,
39+ ) ;
40+ expect ( diskEvidence ) . toEqual ( evidence ) ;
41+ expect ( evidence . schemaVersion ) . toBe ( 2 ) ;
42+ expect ( evidence . entries ) . toHaveLength ( 1 ) ;
43+ expect ( evidence . entries [ 0 ] ) . toMatchObject ( {
44+ coverage : [
45+ { id : "observability.async-dispatch" , role : "primary" } ,
46+ { id : "observability.diagnostic-event-types" , role : "primary" } ,
47+ { id : "observability.model-call-diagnostic-events" , role : "primary" } ,
48+ { id : "observability.plugin-sdk-diagnostic-runtime-exports" , role : "primary" } ,
49+ { id : "observability.trusted-diagnostic-event-subscription" , role : "primary" } ,
50+ { id : "observability.trusted-trace-context" , role : "primary" } ,
51+ { id : "observability.w3c-trace-context-creation" , role : "primary" } ,
52+ ] ,
53+ execution : {
54+ artifacts : [
55+ { kind : "log" , path : "diagnostic-events-boundary.log" , source : "script" } ,
56+ {
57+ kind : "summary" ,
58+ path : "diagnostic-events-boundary-summary.json" ,
59+ source : "script" ,
60+ } ,
61+ ] ,
62+ environment : { ref : checkoutSha } ,
63+ packageSource : { kind : "source-checkout" , sha : checkoutSha } ,
64+ } ,
65+ result : { status : "pass" } ,
66+ test : {
67+ id : "diagnostic-events-boundary" ,
68+ source : { path : "test/e2e/qa-lab/runtime/diagnostic-events-boundary-runtime.ts" } ,
69+ } ,
70+ } ) ;
2771 expect ( summary ) . toMatchObject ( {
2872 deliveredBeforeDrain : 0 ,
2973 eventTypes : [ "model.call.started" , "model.call.completed" ] ,
@@ -43,7 +87,6 @@ describe("diagnostic events boundary runtime", () => {
4387 "utf8" ,
4488 ) ;
4589 expect ( summaryText ) . not . toContain ( "diagnostic-boundary-private-input" ) ;
46- await expect ( fs . stat ( path . join ( artifactBase , "qa-evidence.json" ) ) ) . resolves . toBeDefined ( ) ;
4790 } ) ;
4891
4992 it ( "rejects missing output-dir values" , ( ) => {
0 commit comments