47 lines
2.5 KiB
TypeScript
47 lines
2.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|||
|
|
import test from "node:test";
|
||
|
|
import { mkdtemp, writeFile, readFile, rm } from "node:fs/promises";
|
||
|
|
import os from "node:os";
|
||
|
|
import path from "node:path";
|
||
|
|
import { workspaceSourceLocks } from "../src/capability-language/source-locks.js";
|
||
|
|
|
||
|
|
test("fork lock proposals follow declared fragments and ignore comments and unrelated lock files", async (context) => {
|
||
|
|
const directory = await mkdtemp(path.join(os.tmpdir(), "qx-lock-fork-"));
|
||
|
|
context.after(() => rm(directory, { recursive: true, force: true }));
|
||
|
|
const from = { repository: "https://source.test/app/runtime.git", commit: "b".repeat(40) };
|
||
|
|
const to = { repository: "https://source.test/fork/runtime.git", commit: "c".repeat(40) };
|
||
|
|
const root = `quixos-lock version 1 {
|
||
|
|
quixos source { repository "https://source.test/quixos.git"; commit "${"a".repeat(40)}"; }
|
||
|
|
import "resources.lock";
|
||
|
|
// package Fake source { repository "https://unrelated.test/secret.git"; commit "${"d".repeat(40)}"; }
|
||
|
|
}`;
|
||
|
|
const fragment = `quixos-lock fragment version 1 {
|
||
|
|
// Preserve this note: 雨 📚
|
||
|
|
package Runtime source { repository "${from.repository}"; commit "${from.commit}"; }
|
||
|
|
}`;
|
||
|
|
await writeFile(path.join(directory, "quixos.lock"), root);
|
||
|
|
await writeFile(path.join(directory, "resources.lock"), fragment);
|
||
|
|
await writeFile(path.join(directory, "unrelated.lock"), "This is not a Quixos lock.");
|
||
|
|
const result = await workspaceSourceLocks(directory, [{ from, to }]);
|
||
|
|
assert.equal(result.lock.resources.length, 1);
|
||
|
|
assert.deepEqual(result.lock.resources[0].source, { resolver: "git", ...to });
|
||
|
|
assert.equal(result.files.find((file) => file.path === "quixos.lock")!.source, root);
|
||
|
|
assert.match(result.files.find((file) => file.path === "resources.lock")!.source, /Preserve this note: 雨 📚/);
|
||
|
|
assert.deepEqual(result.files.map((file) => file.path).sort(), ["quixos.lock", "resources.lock"]);
|
||
|
|
assert.equal(
|
||
|
|
await readFile(path.join(directory, "resources.lock"), "utf8"),
|
||
|
|
fragment,
|
||
|
|
"Proposing a fork does not edit selected source",
|
||
|
|
);
|
||
|
|
await assert.rejects(
|
||
|
|
workspaceSourceLocks(directory, [
|
||
|
|
{ from, to },
|
||
|
|
{ from, to },
|
||
|
|
]),
|
||
|
|
/Duplicate/,
|
||
|
|
);
|
||
|
|
await assert.rejects(workspaceSourceLocks(directory, [{ from, to: { ...to, commit: "main" } }]), /exact commit/);
|
||
|
|
await writeFile(path.join(directory, "quixos.lock"), root.replace('"resources.lock"', '"../outside.lock"'));
|
||
|
|
await assert.rejects(workspaceSourceLocks(directory), /Invalid source lock/);
|
||
|
|
});
|