1+ // Verifies models.json writes, plugin catalog writes, and ready-cache serialization.
12import fs from "node:fs/promises" ;
23import path from "node:path" ;
34import { beforeAll , beforeEach , describe , expect , it , vi } from "vitest" ;
@@ -29,6 +30,7 @@ let clearCurrentPluginMetadataSnapshot: typeof import("../plugins/current-plugin
2930let setCurrentPluginMetadataSnapshot : typeof import ( "../plugins/current-plugin-metadata-snapshot.js" ) . setCurrentPluginMetadataSnapshot ;
3031
3132function createPluginMetadataSnapshot ( workspaceDir : string ) : PluginMetadataSnapshot {
33+ // Minimal process snapshot used to prove when metadata may be reused.
3234 const policyHash = resolveInstalledPluginIndexPolicyHash ( { } ) ;
3335 return {
3436 policyHash,
@@ -72,6 +74,7 @@ function createPluginMetadataSnapshot(workspaceDir: string): PluginMetadataSnaps
7274}
7375
7476async function expectMissingPath ( operation : Promise < unknown > ) {
77+ // Filesystem deletion assertions should fail on the errno, not path text.
7578 let error : NodeJS . ErrnoException | undefined ;
7679 try {
7780 await operation ;
@@ -87,6 +90,7 @@ function planParamsAt(callIndex: number): {
8790 providerDiscoveryTimeoutMs ?: number ;
8891 workspaceDir ?: string ;
8992} {
93+ // Planner call shape is the contract between ensureOpenClawModelsJson and planning.
9094 const call = planOpenClawModelsJsonMock . mock . calls [ callIndex ] ;
9195 if ( ! call ) {
9296 throw new Error ( `expected models planner call #${ callIndex + 1 } ` ) ;
@@ -397,6 +401,7 @@ describe("models-config write serialization", () => {
397401 let modelsWriteCount = 0 ;
398402 writePrivateStoreTextWriteMock . mockImplementation (
399403 async ( params : { filePath : string ; rootDir : string ; content : string | Uint8Array } ) => {
404+ // Hold both writes at the store boundary to prove the outer serializer works.
400405 const isModelsWrite = path . basename ( params . filePath ) === "models.json" ;
401406 if ( isModelsWrite ) {
402407 modelsWriteCount += 1 ;
0 commit comments