@@ -3,7 +3,7 @@ import { execFileSync, spawnSync } from "node:child_process";
33import { createHash } from "node:crypto" ;
44import { mkdtempSync , mkdirSync , readFileSync , realpathSync , rmSync , writeFileSync } from "node:fs" ;
55import { tmpdir } from "node:os" ;
6- import { join } from "node:path" ;
6+ import { delimiter , join } from "node:path" ;
77import { DatabaseSync } from "node:sqlite" ;
88import { describe , expect , it } from "vitest" ;
99
@@ -470,7 +470,10 @@ function writeLegacySessionEntriesState(stateDir: string): void {
470470 }
471471}
472472
473- function runSessionStateAssertion ( setup : ( stateDir : string ) => void ) : void {
473+ function runSessionStateAssertion (
474+ setup : ( stateDir : string ) => void | NodeJS . ProcessEnv ,
475+ options : { scenario ?: string ; commands ?: string [ ] } = { } ,
476+ ) : void {
474477 const root = mkdtempSync ( join ( tmpdir ( ) , "openclaw-upgrade-survivor-session-state-" ) ) ;
475478 try {
476479 const stateDir = join ( root , "state" ) ;
@@ -481,17 +484,19 @@ function runSessionStateAssertion(setup: (stateDir: string) => void): void {
481484 writeJson ( join ( stateDir , "agents" , "main" , "sessions" , "legacy-session.json" ) , {
482485 id : "legacy-session" ,
483486 } ) ;
484- setup ( stateDir ) ;
485-
486- execFileSync ( process . execPath , [ ASSERTIONS_PATH , "assert-state" ] , {
487- env : {
488- ...process . env ,
489- OPENCLAW_STATE_DIR : stateDir ,
490- OPENCLAW_TEST_WORKSPACE_DIR : workspace ,
491- OPENCLAW_UPGRADE_SURVIVOR_SCENARIO : "base" ,
492- } ,
493- stdio : "pipe" ,
494- } ) ;
487+ const fixtureEnv = setup ( stateDir ) ;
488+ for ( const command of options . commands ?? [ "assert-state" ] ) {
489+ execFileSync ( process . execPath , [ ASSERTIONS_PATH , command ] , {
490+ env : {
491+ ...process . env ,
492+ ...( fixtureEnv ?? { } ) ,
493+ OPENCLAW_STATE_DIR : stateDir ,
494+ OPENCLAW_TEST_WORKSPACE_DIR : workspace ,
495+ OPENCLAW_UPGRADE_SURVIVOR_SCENARIO : options . scenario ?? "base" ,
496+ } ,
497+ stdio : "pipe" ,
498+ } ) ;
499+ }
495500 } finally {
496501 rmSync ( root , { force : true , recursive : true } ) ;
497502 }
@@ -814,6 +819,67 @@ function assertUpdateRunSelfUpgrade(summary: ReturnType<typeof createUpdateRunSe
814819}
815820
816821describe ( "upgrade survivor assertions" , ( ) => {
822+ it . runIf ( process . platform !== "win32" ) (
823+ "rechecks migrated meeting state before materializing transcript exports" ,
824+ ( ) => {
825+ expect ( ( ) =>
826+ runSessionStateAssertion (
827+ ( stateDir ) => {
828+ writeMigratedSessionState ( stateDir ) ;
829+ const archive = join (
830+ stateDir ,
831+ "transcripts.migrated-fixture" ,
832+ "2026-07-01" ,
833+ "design-review" ,
834+ ) ;
835+ mkdirSync ( archive , { recursive : true } ) ;
836+ writeFileSync (
837+ join ( archive , "transcript.jsonl" ) ,
838+ [ "legacy-u-1" , "legacy-u-2" ] . map ( ( id ) => JSON . stringify ( { id } ) ) . join ( "\n" ) + "\n" ,
839+ ) ;
840+ writeFileSync ( join ( archive , "summary.md" ) , "Shipped transcript summary\n" ) ;
841+ mkdirSync ( join ( stateDir , "state" ) , { recursive : true } ) ;
842+ const db = new DatabaseSync ( join ( stateDir , "state" , "openclaw.sqlite" ) ) ;
843+ try {
844+ db . exec ( `
845+ CREATE TABLE meeting_transcript_sessions (session_id, started_at, next_utterance_seq);
846+ INSERT INTO meeting_transcript_sessions VALUES ('design-review', '2026-07-01T10:00:00.000Z', 2);
847+ CREATE TABLE meeting_transcript_utterances (session_id, sequence, utterance_id, text);
848+ INSERT INTO meeting_transcript_utterances VALUES ('design-review', 0, 'legacy-u-1', 'First shipped transcript line');
849+ INSERT INTO meeting_transcript_utterances VALUES ('design-review', 1, 'legacy-u-2', 'Second shipped transcript line');
850+ CREATE TABLE migration_sources (migration_kind, status, removed_source, source_record_count);
851+ INSERT INTO migration_sources VALUES ('meeting-transcripts-files-v1', 'archived', 1, 2);
852+ ` ) ;
853+ } finally {
854+ db . close ( ) ;
855+ }
856+ const binDir = join ( stateDir , "bin" ) ;
857+ mkdirSync ( binDir ) ;
858+ writeFileSync (
859+ join ( binDir , "openclaw" ) ,
860+ `#!/usr/bin/env node
861+ const assert = require("node:assert/strict");
862+ const fs = require("node:fs");
863+ const path = require("node:path");
864+ assert.deepEqual(process.argv.slice(2), ["transcripts", "path", "2026-07-01/design-review", "--dir"]);
865+ const root = process.env.OPENCLAW_STATE_DIR;
866+ const sessionDir = path.join(root, "transcripts", "2026-07-01", "design-review");
867+ fs.cpSync(path.join(root, "transcripts.migrated-fixture", "2026-07-01", "design-review"), sessionDir, { recursive: true });
868+ process.stdout.write(sessionDir + "\\n");
869+ ` ,
870+ { mode : 0o755 } ,
871+ ) ;
872+ return { PATH : `${ binDir } ${ delimiter } ${ process . env . PATH } ` } ;
873+ } ,
874+ {
875+ scenario : "meeting-transcripts-sqlite" ,
876+ commands : [ "assert-state" , "assert-state" , "assert-meeting-transcript-export" ] ,
877+ } ,
878+ ) ,
879+ ) . not . toThrow ( ) ;
880+ } ,
881+ ) ;
882+
817883 it ( "lists the dependency-free scenario contract" , ( ) => {
818884 const scenarios = JSON . parse (
819885 execFileSync ( process . execPath , [ ASSERTIONS_PATH , "list-scenarios" ] , {
0 commit comments