|
| 1 | +import { afterEach, describe, expect, it } from "vitest"; |
| 2 | +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { join } from "node:path"; |
| 5 | +import { |
| 6 | + isPlanAudioArtifactPath, |
| 7 | + PLAN_AUDIO_LEGACY_RELATIVE_PATH, |
| 8 | + PLAN_AUDIO_RELATIVE_PATH, |
| 9 | + resolvePlanAudioPath, |
| 10 | +} from "./shared.js"; |
| 11 | + |
| 12 | +/** |
| 13 | + * `plan` and `assemble` are separate invocations bridged by object storage, so a |
| 14 | + * rolling deploy can pair a pre-rollout planner with a post-rollout assembler. |
| 15 | + * Both readers locate the artifact by existence alone, which would make that |
| 16 | + * pairing a silently muted video rather than an error. |
| 17 | + * |
| 18 | + * Delete this file, the legacy constant, and the fallback branch one release |
| 19 | + * after the container change ships. |
| 20 | + */ |
| 21 | +describe("plan audio artifact compatibility", () => { |
| 22 | + const dirs: string[] = []; |
| 23 | + |
| 24 | + afterEach(() => { |
| 25 | + for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }); |
| 26 | + }); |
| 27 | + |
| 28 | + const planDir = (files: string[]): string => { |
| 29 | + const dir = mkdtempSync(join(tmpdir(), "hf-plan-audio-")); |
| 30 | + dirs.push(dir); |
| 31 | + for (const name of files) writeFileSync(join(dir, name), "audio"); |
| 32 | + return dir; |
| 33 | + }; |
| 34 | + |
| 35 | + it("prefers the current name", () => { |
| 36 | + const dir = planDir([PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]); |
| 37 | + expect(resolvePlanAudioPath(dir)).toBe(join(dir, PLAN_AUDIO_RELATIVE_PATH)); |
| 38 | + }); |
| 39 | + |
| 40 | + it("falls back to a legacy plan's name so a rolling deploy keeps its audio", () => { |
| 41 | + const dir = planDir([PLAN_AUDIO_LEGACY_RELATIVE_PATH]); |
| 42 | + expect(resolvePlanAudioPath(dir)).toBe(join(dir, PLAN_AUDIO_LEGACY_RELATIVE_PATH)); |
| 43 | + }); |
| 44 | + |
| 45 | + it("reports no audio when the plan carries neither name", () => { |
| 46 | + expect(resolvePlanAudioPath(planDir([]))).toBeNull(); |
| 47 | + }); |
| 48 | + |
| 49 | + it("recognises both names as the audio artifact, and nothing else", () => { |
| 50 | + expect(isPlanAudioArtifactPath(PLAN_AUDIO_RELATIVE_PATH)).toBe(true); |
| 51 | + expect(isPlanAudioArtifactPath(PLAN_AUDIO_LEGACY_RELATIVE_PATH)).toBe(true); |
| 52 | + expect(isPlanAudioArtifactPath("plan.json")).toBe(false); |
| 53 | + expect(isPlanAudioArtifactPath("meta/chunks.json")).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + it("writes only the current name", () => { |
| 57 | + expect(PLAN_AUDIO_RELATIVE_PATH).not.toBe(PLAN_AUDIO_LEGACY_RELATIVE_PATH); |
| 58 | + expect(PLAN_AUDIO_RELATIVE_PATH.endsWith(".m4a")).toBe(true); |
| 59 | + }); |
| 60 | +}); |
0 commit comments