mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-29 08:06:46 +00:00
Dev servers bind to localhost by default (new --host option) and sync keeps paths within the project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { afterAll, describe, expect, test } from "bun:test";
|
|
import {
|
|
mkdirSync,
|
|
mkdtempSync,
|
|
rmSync,
|
|
symlinkSync,
|
|
writeFileSync,
|
|
} from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { inlinePathWithin, readInlinePathSync } from "../src/utils/utils.ts";
|
|
import { validateInlineResourcePointer } from "../src/commands/resource/resource.ts";
|
|
|
|
const scratch = mkdtempSync(join(tmpdir(), "wmill-inline-"));
|
|
const root = join(scratch, "repo");
|
|
const outside = join(scratch, "outside.txt");
|
|
mkdirSync(join(root, "f", "res"), { recursive: true });
|
|
writeFileSync(join(root, "f", "res", "conf.resource.file.ini"), "inside");
|
|
writeFileSync(outside, "outside");
|
|
symlinkSync(outside, join(root, "f", "res", "link.resource.file.ini"));
|
|
|
|
afterAll(() => rmSync(scratch, { recursive: true, force: true }));
|
|
|
|
describe("inline references", () => {
|
|
test("keeps inline references inside the sync directory", () => {
|
|
expect(readInlinePathSync("f/res/conf.resource.file.ini", root)).toBe(
|
|
"inside",
|
|
);
|
|
for (const ref of [
|
|
"../outside.txt",
|
|
"f/../../outside.txt",
|
|
outside,
|
|
"f/res/link.resource.file.ini",
|
|
]) {
|
|
expect(() => inlinePathWithin(ref, root)).toThrow(/outside/);
|
|
expect(() => readInlinePathSync(ref, root)).toThrow(/outside/);
|
|
}
|
|
});
|
|
|
|
test("a missing file inside the directory is left to the reader", () => {
|
|
expect(inlinePathWithin("f/res/missing.txt", root)).toBe(
|
|
join(root, "f", "res", "missing.txt"),
|
|
);
|
|
});
|
|
|
|
test("a synced resource reads only its own content file", () => {
|
|
validateInlineResourcePointer("f/res/conf.resource.file.ini", "f/res/conf");
|
|
validateInlineResourcePointer(
|
|
"f/res/conf.prod.resource.file.ini",
|
|
"f/res/conf",
|
|
"f/res/conf.prod.resource.yaml",
|
|
);
|
|
for (const ref of [
|
|
"f/res/other.resource.file.ini",
|
|
"f/res/conf.resource.file.",
|
|
"f/res/conf.resource.file.x/../../y",
|
|
"../.config/windmill/remotes.ndjson",
|
|
]) {
|
|
expect(() => validateInlineResourcePointer(ref, "f/res/conf")).toThrow(
|
|
/content file must live next to it/,
|
|
);
|
|
}
|
|
});
|
|
});
|