Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(sdk): fs adapter flush() tracks in-flight writes; add to T13 contract suite (#1425)
Vance Ingalls0a30011abd18
diff --git a/packages/sdk/src/adapters/fs.ts b/packages/sdk/src/adapters/fs.tsindex b1f7e475b8..615015a7f7 100644--- a/packages/sdk/src/adapters/fs.ts+++ b/packages/sdk/src/adapters/fs.ts@@ -18,6 +18,7 @@ class FsAdapter implements PersistAdapter {private readonly root: string;private readonly maxVersions: number;private errorHandlers: Array<(e: PersistErrorEvent) => void> = [];+ private readonly inflightWrites = new Set<Promise<void>>();private _writeLocks = new Map<string, Promise<void>>();constructor(opts: FsAdapterOptions) {@@ -35,6 +36,16 @@ class FsAdapter implements PersistAdapter {}async write(path: string, content: string): Promise<void> {+ const p = this.doWrite(path, content);+ this.inflightWrites.add(p);+ try {+ await p;+ } finally {+ this.inflightWrites.delete(p);+ }+ }++ private async doWrite(path: string, content: string): Promise<void> {try {const abs = this.abs(path);await mkdir(dirname(abs), { recursive: true });@@ -45,7 +56,11 @@ class FsAdapter implements PersistAdapter {}}- async flush(): Promise<void> {}+ async flush(): Promise<void> {+ // Promise.all rejects on the first write failure; per-write errors are also+ // surfaced individually through the persist:error event channel.+ await Promise.all([...this.inflightWrites]);+ }async listVersions(path: string): Promise<PersistVersionEntry[]> {const dir = this.versionsDir(path);diff --git a/packages/sdk/src/adapters/persistAdapter.contract.test.ts b/packages/sdk/src/adapters/persistAdapter.contract.test.tsindex d03e689302..4d0bb06c92 100644--- a/packages/sdk/src/adapters/persistAdapter.contract.test.ts+++ b/packages/sdk/src/adapters/persistAdapter.contract.test.ts@@ -9,8 +9,12 @@* runPersistAdapterContract("s3", () => createS3Adapter({ bucket, prefix }))*/+import { mkdtempSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";import { describe, it, expect, vi } from "vitest";import { createMemoryAdapter } from "./memory.js";+import { createFsAdapter } from "./fs.js";import type { PersistAdapter } from "./types.js";export function runPersistAdapterContract(@@ -126,3 +130,8 @@ export function runPersistAdapterContract(// Run the suite against the memory adapter immediatelyrunPersistAdapterContract("memory", createMemoryAdapter);++// Run against the fs adapter — each test gets an isolated tmpdir+runPersistAdapterContract("fs", () =>+ createFsAdapter({ root: mkdtempSync(join(tmpdir(), "hf-fs-test-")) }),+);