import { expect, test } from "bun:test"; import { join } from "node:path"; import { remoteKeyWithinFolder } from "../src/commands/sync/sync.ts"; const FILESET = join("f", "res", "data.fileset"); test("fileset keys and module names land inside their folder", () => { expect(remoteKeyWithinFolder(FILESET, "q.sql")).toBe(join(FILESET, "q.sql")); expect(remoteKeyWithinFolder(FILESET, "models/staging/a.sql")).toBe( join(FILESET, "models", "staging", "a.sql"), ); }); test("fileset keys that are not plain relative paths are refused", () => { for (const key of [ "../cleanup.sh", "a/../../b.sh", "/etc/cron.d/x", "C:/x.ts", "a\\..\\..\\b.ts", "a\0b", "a//b", "./a", "", ]) { expect(() => remoteKeyWithinFolder(FILESET, key)).toThrow( /must be a relative path/, ); } });