Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/cli/src/auto/work-transcribe.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { type ArgsDef, type CommandDef, parseArgs } from "citty";
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, it } from "vitest";
import transcribeCommand from "../commands/transcribe.js";
import { assertKnownFlags } from "../utils/reject-unknown-flags.js";
import { useCli } from "./cutouts.js";
import { transcribe } from "./work.js";

const made: string[] = [];
afterEach(() => made.splice(0).forEach((dir) => rmSync(dir, { recursive: true, force: true })));

it("runs the CLI's own transcribe on the clip, writing into the folder it was given", async () => {
const root = realpathSync(mkdtempSync(join(tmpdir(), "hf-auto-transcribe-")));
made.push(root);
const project = join(root, "project");
const into = join(root, "work", "transcribed");
mkdirSync(project);
mkdirSync(into, { recursive: true });
const seen = join(root, "seen.json");
const child = join(root, "child.mjs");
writeFileSync(
child,
`import { writeFileSync } from "node:fs";
writeFileSync(${JSON.stringify(seen)}, JSON.stringify({ argv: process.argv.slice(2), cwd: process.cwd() }));`,
);
useCli(process.execPath, [child]);
const clip = join(project, "uploads", "clip.mp4");

await transcribe(project, clip, into);

const { argv, cwd } = JSON.parse(readFileSync(seen, "utf8")) as { argv: string[]; cwd: string };
expect(argv[0]).toBe("transcribe");
const command = transcribeCommand as unknown as CommandDef<ArgsDef>;
const raw = argv.slice(1);
expect(() => assertKnownFlags(command, raw, "transcribe")).not.toThrow();
const args = parseArgs(raw, command.args as ArgsDef);
expect(args.input).toBe(clip);
expect(args.dir).toBe(into);
expect(cwd).toBe(project);
});
2 changes: 1 addition & 1 deletion packages/cli/src/auto/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class Work {
const execFileAsync = promisify(execFile);

/** The CLI's own transcribe, run as a command so its model and progress stay its own. */
async function transcribe(project: string, clip: string, into: string): Promise<void> {
export async function transcribe(project: string, clip: string, into: string): Promise<void> {
const [command, args] = selfCommand(["transcribe", clip, "--dir", into]);
await execFileAsync(command, args, {
cwd: project,
Expand Down
Loading