Merge commit '5100a1a1a56b810c8246b8c7ed19ff42c4d9dbe1' into fix/ci-duplicate-boundaries-1603
This commit is contained in:
@@ -69,6 +69,35 @@ describe("artifact inventory entry order", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves deep ZIP members without inventing missing directories", async () => {
|
||||
const root = await createTestTempDirectory("rea-deep-archive-parent-");
|
||||
const archive = join(root, "deep.zip");
|
||||
// Fits the ZIP filename field while exceeding the formerly expensive depth.
|
||||
const members = ["data.txt", "second.txt", "third.bin"].map(
|
||||
(name) => `observed/${"d/".repeat(30_000)}${name}`,
|
||||
);
|
||||
await writeOrderedZip(archive, [...members, "observed/", "unrelated/"]);
|
||||
const inventory = await inventoryArtifact(archive);
|
||||
expect(artifactParentPaths(inventory)).toEqual({
|
||||
".": null,
|
||||
observed: ".",
|
||||
unrelated: ".",
|
||||
...Object.fromEntries(members.map((member) => [member, "observed"])),
|
||||
});
|
||||
const observedParent = artifactOccurrenceAt(inventory, "observed");
|
||||
for (const member of members) {
|
||||
const occurrence = artifactOccurrenceAt(inventory, member);
|
||||
expect(occurrence.hash_status).toBe("verified");
|
||||
expect(inventory.edges).toContainEqual(
|
||||
expect.objectContaining({
|
||||
occurrence_id: occurrence.occurrence_id,
|
||||
parent_artifact_id: observedParent.artifact_id,
|
||||
relation: "contains",
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
entries: ["pkg/sub/data.txt"],
|
||||
@@ -129,6 +158,61 @@ describe("entry-order validation and reader controls", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("retains high-cardinality case-folded directories and their descendants", async () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-entry-order-case-capacity-",
|
||||
);
|
||||
const archive = join(root, "case-capacity.zip");
|
||||
const variants = Array.from({ length: 256 }, (_, mask) =>
|
||||
[..."abcdefgh"]
|
||||
.map((character, index) =>
|
||||
(mask & (1 << index)) === 0 ? character : character.toUpperCase(),
|
||||
)
|
||||
.join(""),
|
||||
);
|
||||
await writeOrderedZip(
|
||||
archive,
|
||||
variants.flatMap((variant) => [variant + "/", variant + "/entry.txt"]),
|
||||
);
|
||||
|
||||
const inventory = await inventoryArtifact(archive);
|
||||
const directories = variants.map((variant) =>
|
||||
artifactOccurrenceAt(inventory, variant),
|
||||
);
|
||||
const descendants = variants.map((variant) =>
|
||||
artifactOccurrenceAt(inventory, `${variant}/entry.txt`),
|
||||
);
|
||||
const ordered = [...variants].sort();
|
||||
const first = ordered[0];
|
||||
const second = ordered[1];
|
||||
|
||||
expect(inventory.occurrences).toHaveLength(1 + variants.length * 2);
|
||||
expect(
|
||||
new Set(inventory.occurrences.map(({ logical_path }) => logical_path))
|
||||
.size,
|
||||
).toBe(1 + variants.length * 2);
|
||||
expect(
|
||||
new Set(
|
||||
[...directories, ...descendants].map(
|
||||
({ occurrence_id }) => occurrence_id,
|
||||
),
|
||||
).size,
|
||||
).toBe(variants.length * 2);
|
||||
expect(
|
||||
directories.every(({ limitations }) => limitations.length === 1),
|
||||
).toBe(true);
|
||||
expect(
|
||||
descendants.every(({ limitations }) => limitations.length === 1),
|
||||
).toBe(true);
|
||||
expect(
|
||||
directories.find(({ logical_path }) => logical_path === first)
|
||||
?.limitations[0],
|
||||
).toContain(`with ${second} and 254 other spellings;`);
|
||||
expect(descendants[0]?.limitations[0]).toContain(
|
||||
`is under ${variants[0]}, which collides under English (en-US) Unicode case folding with ${first} and 254 other spellings;`,
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves ordinary directory and ASAR structure", async () => {
|
||||
const root = await createTestTempDirectory("rea-entry-order-readers-");
|
||||
const directory = join(root, "source");
|
||||
|
||||
@@ -305,19 +305,22 @@ describe("ASAR read failures", () => {
|
||||
errno: -5,
|
||||
syscall: "fstat",
|
||||
});
|
||||
const closeError = Object.assign(new Error("device close failed"), {
|
||||
code: "EIO",
|
||||
errno: -5,
|
||||
syscall: "close",
|
||||
});
|
||||
let closeCount = 0;
|
||||
const reader = new AsarArtifactReader(archive, async (path, flags) => {
|
||||
const handle = await openFile(path, flags);
|
||||
expect(await matchingDescriptorCount(identity)).toBeGreaterThan(0);
|
||||
let statCount = 0;
|
||||
return {
|
||||
async stat() {
|
||||
statCount += 1;
|
||||
if (statCount === 2) throw ioError;
|
||||
return handle.stat();
|
||||
throw ioError;
|
||||
},
|
||||
async close() {
|
||||
closeCount += 1;
|
||||
if (closeCount === 1) throw closeError;
|
||||
await handle.close();
|
||||
},
|
||||
createReadStream: (options) => handle.createReadStream(options),
|
||||
@@ -337,73 +340,320 @@ describe("ASAR read failures", () => {
|
||||
message: expect.stringContaining(
|
||||
`Could not read ${entry.path} ASAR at ${archive}: device stat failed`,
|
||||
),
|
||||
cause: { code: "EIO", errno: -5, syscall: "fstat" },
|
||||
cause: {
|
||||
reason: "io",
|
||||
cause: { code: "EIO", errno: -5, syscall: "fstat" },
|
||||
},
|
||||
cleanup: {
|
||||
resources: [unpackedPath],
|
||||
reason: "device close failed",
|
||||
},
|
||||
});
|
||||
expect(closeCount).toBe(1);
|
||||
expect(await matchingDescriptorCount(identity)).toBeGreaterThan(0);
|
||||
await reader.close();
|
||||
expect(closeCount).toBe(2);
|
||||
await waitForNoMatchingDescriptor(identity);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["missing", "replaced"] as const)(
|
||||
"reads a captured zero-length member when the original container is %s",
|
||||
async (change) => {
|
||||
const root = await createTestTempDirectory("rea-asar-empty-member-");
|
||||
const source = join(root, "source");
|
||||
const archive = join(root, "fixture.asar");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "empty.js"), "");
|
||||
await createPackageWithOptions(source, archive, {});
|
||||
const reader = new AsarArtifactReader(archive);
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"retries cleanup when cancellation arrives immediately after unpacked stat",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-unpacked-abort-stat-");
|
||||
const source = join(root, "source");
|
||||
const archive = join(root, "fixture.asar");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "small.js"), "module.exports = 1;\n");
|
||||
await createPackageWithOptions(source, archive, { unpack: "small.js" });
|
||||
const unpackedPath = join(`${archive}.unpacked`, "small.js");
|
||||
const identity = await lstat(unpackedPath);
|
||||
const controller = new AbortController();
|
||||
let closeCount = 0;
|
||||
const reader = new AsarArtifactReader(archive, async (path, flags) => {
|
||||
const handle = await openFile(path, flags);
|
||||
return {
|
||||
async stat() {
|
||||
const observed = await handle.stat();
|
||||
controller.abort();
|
||||
return observed;
|
||||
},
|
||||
async close() {
|
||||
closeCount += 1;
|
||||
if (closeCount === 1) throw new Error("first close failed");
|
||||
await handle.close();
|
||||
},
|
||||
createReadStream: (options) => handle.createReadStream(options),
|
||||
};
|
||||
});
|
||||
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
const entry = entries.find(({ path }) => path === "empty.js");
|
||||
if (entry === undefined) throw new Error("Expected empty ASAR member");
|
||||
if (change === "missing") await rm(archive);
|
||||
else await writeFile(archive, "replacement container");
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
const entry = entries.find(({ path }) => path === "small.js");
|
||||
if (entry === undefined) throw new Error("Expected unpacked ASAR member");
|
||||
|
||||
expect(await buffer(await reader.open(entry))).toHaveLength(0);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
await expect(reader.open(entry, controller.signal)).rejects.toMatchObject(
|
||||
{
|
||||
reason: "cancelled",
|
||||
cleanup: {
|
||||
resources: [unpackedPath],
|
||||
reason: "first close failed",
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(closeCount).toBe(1);
|
||||
expect(await matchingDescriptorCount(identity)).toBeGreaterThan(0);
|
||||
await reader.close();
|
||||
expect(closeCount).toBe(2);
|
||||
await waitForNoMatchingDescriptor(identity);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"preserves an unpacked identity failure when closing its handle fails",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-unpacked-identity-");
|
||||
const source = join(root, "source");
|
||||
const archive = join(root, "fixture.asar");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "small.js"), "module.exports = 1;\n");
|
||||
await createPackageWithOptions(source, archive, { unpack: "small.js" });
|
||||
const unpackedPath = join(`${archive}.unpacked`, "small.js");
|
||||
const identity = await lstat(unpackedPath);
|
||||
const closeError = new Error("first close failed");
|
||||
let closeCount = 0;
|
||||
const reader = new AsarArtifactReader(archive, async (path, flags) => {
|
||||
const handle = await openFile(path, flags);
|
||||
return {
|
||||
async stat() {
|
||||
const observed = await handle.stat();
|
||||
return Object.assign(Object.create(observed), {
|
||||
ino: observed.ino + 1,
|
||||
});
|
||||
},
|
||||
async close() {
|
||||
closeCount += 1;
|
||||
if (closeCount === 1) throw closeError;
|
||||
await handle.close();
|
||||
},
|
||||
createReadStream: (options) => handle.createReadStream(options),
|
||||
};
|
||||
});
|
||||
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
const entry = entries.find(({ path }) => path === "small.js");
|
||||
if (entry === undefined) throw new Error("Expected unpacked ASAR member");
|
||||
|
||||
await expect(reader.open(entry)).rejects.toMatchObject({
|
||||
name: "ArtifactReaderFailure",
|
||||
reason: "integrity",
|
||||
message: expect.stringContaining(
|
||||
`ASAR unpacked entry changed before read: ${entry.path}`,
|
||||
),
|
||||
cleanup: {
|
||||
resources: [unpackedPath],
|
||||
reason: "first close failed",
|
||||
},
|
||||
});
|
||||
expect(closeCount).toBe(1);
|
||||
expect(await matchingDescriptorCount(identity)).toBeGreaterThan(0);
|
||||
await reader.close();
|
||||
expect(closeCount).toBe(2);
|
||||
await waitForNoMatchingDescriptor(identity);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"retains unpacked handles and snapshots across combined cleanup failures",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-combined-cleanup-");
|
||||
const source = join(root, "source");
|
||||
const archive = join(root, "fixture.asar");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "small.js"), "module.exports = 1;\n");
|
||||
await createPackageWithOptions(source, archive, { unpack: "small.js" });
|
||||
const unpackedPath = join(`${archive}.unpacked`, "small.js");
|
||||
const identity = await lstat(unpackedPath);
|
||||
const closeError = new Error("unpacked close denied");
|
||||
const snapshotError = new Error("snapshot removal denied");
|
||||
let closeCount = 0;
|
||||
const snapshotPaths: string[] = [];
|
||||
const reader = new AsarArtifactReader(
|
||||
archive,
|
||||
async (path, flags) => {
|
||||
const handle = await openFile(path, flags);
|
||||
return {
|
||||
async stat() {
|
||||
throw Object.assign(new Error("device stat failed"), {
|
||||
code: "EIO",
|
||||
errno: -5,
|
||||
syscall: "fstat",
|
||||
});
|
||||
},
|
||||
async close() {
|
||||
closeCount += 1;
|
||||
if (closeCount < 3) throw closeError;
|
||||
await handle.close();
|
||||
},
|
||||
createReadStream: (options) => handle.createReadStream(options),
|
||||
};
|
||||
},
|
||||
async (path) => {
|
||||
snapshotPaths.push(path);
|
||||
if (snapshotPaths.length === 1) throw snapshotError;
|
||||
await rm(path, { recursive: true, force: true });
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
const entry = entries.find(({ path }) => path === "small.js");
|
||||
if (entry === undefined) throw new Error("Expected unpacked ASAR member");
|
||||
|
||||
await expect(reader.open(entry)).rejects.toMatchObject({
|
||||
reason: "io",
|
||||
cleanup: { resources: [unpackedPath] },
|
||||
});
|
||||
expect(closeCount).toBe(1);
|
||||
|
||||
const cleanupFailure = await reader.close().then(
|
||||
() => undefined,
|
||||
(cause: unknown) => cause,
|
||||
);
|
||||
expect(cleanupFailure).toMatchObject({
|
||||
cleanup: {
|
||||
resources: [unpackedPath, expect.any(String)],
|
||||
reason: expect.stringContaining("unpacked close denied"),
|
||||
},
|
||||
});
|
||||
const snapshotRoot = snapshotPaths[0];
|
||||
if (snapshotRoot === undefined)
|
||||
throw new Error("Expected owned ASAR snapshot root");
|
||||
expect(snapshotPaths).toEqual([snapshotRoot]);
|
||||
expect(cleanupFailure).toMatchObject({
|
||||
cleanup: { resources: [unpackedPath, snapshotRoot] },
|
||||
});
|
||||
expect(closeCount).toBe(2);
|
||||
expect(await matchingDescriptorCount(identity)).toBeGreaterThan(0);
|
||||
expect((await lstat(snapshotRoot)).isDirectory()).toBe(true);
|
||||
|
||||
await reader.close();
|
||||
expect(closeCount).toBe(3);
|
||||
expect(snapshotPaths).toEqual([snapshotRoot, snapshotRoot]);
|
||||
await waitForNoMatchingDescriptor(identity);
|
||||
await expect(lstat(snapshotRoot)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"releases unpacked handles after stream completion and cancellation",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-unpacked-stream-");
|
||||
const source = join(root, "source");
|
||||
const archive = join(root, "fixture.asar");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "small.js"), "module.exports = 1;\n");
|
||||
await createPackageWithOptions(source, archive, { unpack: "small.js" });
|
||||
const identity = await lstat(join(`${archive}.unpacked`, "small.js"));
|
||||
const reader = new AsarArtifactReader(archive);
|
||||
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
const entry = entries.find(({ path }) => path === "small.js");
|
||||
if (entry === undefined) throw new Error("Expected unpacked ASAR member");
|
||||
expect((await buffer(await reader.open(entry))).toString()).toBe(
|
||||
"module.exports = 1;\n",
|
||||
);
|
||||
await waitForNoMatchingDescriptor(identity);
|
||||
|
||||
const controller = new AbortController();
|
||||
const output = await reader.open(entry, controller.signal);
|
||||
const reading = buffer(output);
|
||||
controller.abort();
|
||||
await expect(reading).rejects.toMatchObject({ reason: "cancelled" });
|
||||
await waitForNoMatchingDescriptor(identity);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["missing", "replaced"] as const)(
|
||||
"reads a captured zero-length member when the original container is %s",
|
||||
async (change) => {
|
||||
const root = await createTestTempDirectory("rea-asar-empty-member-");
|
||||
const source = join(root, "source");
|
||||
const archive = join(root, "fixture.asar");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "empty.js"), "");
|
||||
await createPackageWithOptions(source, archive, {});
|
||||
const reader = new AsarArtifactReader(archive);
|
||||
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
const entry = entries.find(({ path }) => path === "empty.js");
|
||||
if (entry === undefined) throw new Error("Expected empty ASAR member");
|
||||
if (change === "missing") await rm(archive);
|
||||
else await writeFile(archive, "replacement container");
|
||||
|
||||
expect(await buffer(await reader.open(entry))).toHaveLength(0);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves filesystem errors raised while consuming a member stream", async () => {
|
||||
const ioError = Object.assign(new Error("device read failed"), {
|
||||
code: "EIO",
|
||||
errno: -5,
|
||||
syscall: "read",
|
||||
});
|
||||
const source = Readable.from(
|
||||
(async function* () {
|
||||
yield Buffer.from("partial");
|
||||
throw ioError;
|
||||
})(),
|
||||
);
|
||||
const output = readValidatedAsarEntry(
|
||||
source,
|
||||
undefined,
|
||||
"nested/member.bin",
|
||||
"/tmp/source.asar",
|
||||
);
|
||||
|
||||
it("preserves filesystem errors raised while consuming a member stream", async () => {
|
||||
const ioError = Object.assign(new Error("device read failed"), {
|
||||
code: "EIO",
|
||||
errno: -5,
|
||||
syscall: "read",
|
||||
});
|
||||
const source = Readable.from(
|
||||
(async function* () {
|
||||
yield Buffer.from("partial");
|
||||
throw ioError;
|
||||
})(),
|
||||
);
|
||||
const output = readValidatedAsarEntry(
|
||||
source,
|
||||
undefined,
|
||||
"nested/member.bin",
|
||||
"/tmp/source.asar",
|
||||
);
|
||||
|
||||
await expect(async () => {
|
||||
for await (const _chunk of output) {
|
||||
// Consume through the source failure.
|
||||
}
|
||||
}).rejects.toMatchObject({
|
||||
name: "ArtifactReaderFailure",
|
||||
reason: "io",
|
||||
message: expect.stringContaining(
|
||||
"Could not read nested/member.bin ASAR at /tmp/source.asar",
|
||||
),
|
||||
cause: { code: "EIO", errno: -5, syscall: "read" },
|
||||
});
|
||||
await expect(async () => {
|
||||
for await (const _chunk of output) {
|
||||
// Consume through the source failure.
|
||||
}
|
||||
}).rejects.toMatchObject({
|
||||
name: "ArtifactReaderFailure",
|
||||
reason: "io",
|
||||
message: expect.stringContaining(
|
||||
"Could not read nested/member.bin ASAR at /tmp/source.asar",
|
||||
),
|
||||
cause: { code: "EIO", errno: -5, syscall: "read" },
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { parse as parseJsonc } from "jsonc-parser";
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js";
|
||||
import { systemSetupHost } from "../../../src/application/SetupHost.js";
|
||||
import { MANAGED_SKILL_FILES } from "../../../src/application/SetupSkill.js";
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import { systemUninstallHost } from "../../../src/application/Uninstall.js";
|
||||
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
||||
@@ -151,6 +152,7 @@ describe("Qwen Code profile setup", () => {
|
||||
});
|
||||
expect(await setup.installSkill([client.name])).toBe("installed");
|
||||
const skill = join(home, ".agents", "skills", PRODUCT_IDENTITY.skillName);
|
||||
await writeFile(join(skill, "user-notes.txt"), "user-authored");
|
||||
expect(await readFile(join(skill, "SKILL.md"), "utf8")).toContain(
|
||||
"reverse-engineer-anything",
|
||||
);
|
||||
@@ -173,7 +175,13 @@ describe("Qwen Code profile setup", () => {
|
||||
expect(registered).toEqual(client);
|
||||
expect((await uninstall.removeClient(client)).status).toBe("removed");
|
||||
expect((await uninstall.removeSkill()).status).toBe("removed");
|
||||
await expect(access(skill)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
for (const relativePath of MANAGED_SKILL_FILES)
|
||||
await expect(access(join(skill, relativePath))).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
expect(await readFile(join(skill, "user-notes.txt"), "utf8")).toBe(
|
||||
"user-authored",
|
||||
);
|
||||
if (customHome)
|
||||
await expect(access(join(home, ".qwen"))).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
|
||||
@@ -2,10 +2,14 @@ import { createHash } from "node:crypto";
|
||||
import {
|
||||
access,
|
||||
chmod,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
readlink,
|
||||
rename,
|
||||
rm,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
@@ -17,7 +21,7 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { SafeOutputTree } from "../../../src/artifacts/SafeOutputTree.js";
|
||||
import { ArtifactReaderFailure } from "../../../src/artifacts/ArtifactReader.js";
|
||||
|
||||
describe("safe artifact output tree", () => {
|
||||
describe("safe artifact output cleanup", () => {
|
||||
it.skipIf(process.platform !== "linux")(
|
||||
"closes the parent descriptor when the output disappears before commit",
|
||||
async () => {
|
||||
@@ -32,12 +36,169 @@ describe("safe artifact output tree", () => {
|
||||
),
|
||||
);
|
||||
expect(targets.filter((target) => target === parent)).toEqual([]);
|
||||
const failure = await tree.rollback().catch((cause: unknown) => cause);
|
||||
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(failure).toMatchObject({ cleanup: { resources: [output] } });
|
||||
expect(tree.cleanup).toEqual({
|
||||
status: "incomplete",
|
||||
residualPaths: ["published"],
|
||||
});
|
||||
await rm(parent, { recursive: true, force: true });
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("safe artifact output tree identity", () => {
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"refuses a replaced root and retries cleanup when the owned root is restored",
|
||||
async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-root-");
|
||||
const output = join(parent, "published");
|
||||
const displaced = join(parent, "owned-original");
|
||||
const outside = join(parent, "outside");
|
||||
await mkdir(outside);
|
||||
const tree = await SafeOutputTree.create(output);
|
||||
await rename(output, displaced);
|
||||
await symlink(outside, output, "dir");
|
||||
|
||||
const writeFailure = await tree
|
||||
.write("escaped.txt", Readable.from(Buffer.from("outside")), {
|
||||
sha256: createHash("sha256").update("outside").digest("hex"),
|
||||
bytes: Buffer.byteLength("outside"),
|
||||
})
|
||||
.catch((cause: unknown) => cause);
|
||||
expect(writeFailure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
await expect(access(join(outside, "escaped.txt"))).rejects.toThrow();
|
||||
await expect(tree.commit()).rejects.toBeInstanceOf(ArtifactReaderFailure);
|
||||
const cleanupFailure = await tree
|
||||
.rollback()
|
||||
.catch((cause: unknown) => cause);
|
||||
expect(cleanupFailure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(cleanupFailure).toMatchObject({
|
||||
cleanup: { resources: [output] },
|
||||
});
|
||||
expect(await readlink(output)).toBe(outside);
|
||||
|
||||
await rm(output);
|
||||
await rename(displaced, output);
|
||||
expect(await tree.rollback()).toEqual({
|
||||
status: "complete",
|
||||
residualPaths: [],
|
||||
});
|
||||
expect(await readdir(parent)).toEqual(["outside"]);
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"refuses a replaced nested parent without touching it and retries after restoration",
|
||||
async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-parent-");
|
||||
const output = join(parent, "published");
|
||||
const nested = join(output, "nested");
|
||||
const displaced = join(parent, "owned-nested");
|
||||
const outside = join(parent, "outside");
|
||||
await mkdir(outside);
|
||||
await writeFile(join(outside, "sentinel.txt"), "keep");
|
||||
const tree = await SafeOutputTree.create(output);
|
||||
const bytes = Buffer.from("owned");
|
||||
await tree.write("nested/owned.txt", Readable.from(bytes), {
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.byteLength,
|
||||
});
|
||||
await rename(nested, displaced);
|
||||
await symlink(outside, nested, "dir");
|
||||
|
||||
const writeFailure = await tree
|
||||
.write("nested/escaped.txt", Readable.from(Buffer.from("outside")), {
|
||||
sha256: createHash("sha256").update("outside").digest("hex"),
|
||||
bytes: Buffer.byteLength("outside"),
|
||||
})
|
||||
.catch((cause: unknown) => cause);
|
||||
expect(writeFailure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
await expect(access(join(outside, "escaped.txt"))).rejects.toThrow();
|
||||
expect(await readFile(join(outside, "sentinel.txt"), "utf8")).toBe(
|
||||
"keep",
|
||||
);
|
||||
const cleanupFailure = await tree
|
||||
.rollback()
|
||||
.catch((cause: unknown) => cause);
|
||||
expect(cleanupFailure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(await readlink(nested)).toBe(outside);
|
||||
expect(await readFile(join(outside, "sentinel.txt"), "utf8")).toBe(
|
||||
"keep",
|
||||
);
|
||||
|
||||
await rm(nested);
|
||||
await rename(displaced, nested);
|
||||
expect(await tree.rollback()).toEqual({
|
||||
status: "complete",
|
||||
residualPaths: [],
|
||||
});
|
||||
expect(await readdir(parent)).toEqual(["outside"]);
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"preserves an outside file when a tracked output file is replaced by a symlink",
|
||||
async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-file-");
|
||||
const output = join(parent, "published");
|
||||
const tracked = join(output, "nested", "file.txt");
|
||||
const displaced = join(parent, "owned-file.txt");
|
||||
const outside = join(parent, "outside.txt");
|
||||
await writeFile(outside, "outside bytes");
|
||||
const tree = await SafeOutputTree.create(output);
|
||||
const bytes = Buffer.from("owned bytes");
|
||||
await tree.write("nested/file.txt", Readable.from(bytes), {
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.byteLength,
|
||||
});
|
||||
await rename(tracked, displaced);
|
||||
await symlink(outside, tracked, "file");
|
||||
|
||||
const failure = await tree.rollback().catch((cause: unknown) => cause);
|
||||
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(tree.cleanup).toMatchObject({ status: "incomplete" });
|
||||
expect(await readlink(tracked)).toBe(outside);
|
||||
expect(await readFile(outside, "utf8")).toBe("outside bytes");
|
||||
|
||||
await rm(tracked);
|
||||
await rename(displaced, tracked);
|
||||
expect(await tree.rollback()).toEqual({
|
||||
status: "complete",
|
||||
residualPaths: [],
|
||||
});
|
||||
expect(await readFile(outside, "utf8")).toBe("outside bytes");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("retains an untracked regular entry and retries after it is removed", async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-untracked-");
|
||||
const output = join(parent, "published");
|
||||
const untracked = join(output, "untracked.txt");
|
||||
const tree = await SafeOutputTree.create(output);
|
||||
const bytes = Buffer.from("owned bytes");
|
||||
await tree.write("owned.txt", Readable.from(bytes), {
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.byteLength,
|
||||
});
|
||||
await writeFile(untracked, "leave untouched");
|
||||
|
||||
const failure = await tree.rollback().catch((cause: unknown) => cause);
|
||||
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(tree.cleanup).toMatchObject({ status: "incomplete" });
|
||||
expect(await readdir(output)).toEqual(["untracked.txt"]);
|
||||
expect(await readFile(untracked, "utf8")).toBe("leave untouched");
|
||||
|
||||
await rm(untracked);
|
||||
expect(await tree.rollback()).toEqual({
|
||||
status: "complete",
|
||||
residualPaths: [],
|
||||
});
|
||||
expect(await readdir(parent)).toEqual([]);
|
||||
});
|
||||
describe("safe artifact output tree", () => {
|
||||
it("removes only its owned tree after digest failure and proves absence", async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-");
|
||||
const output = join(parent, "published");
|
||||
@@ -72,6 +233,7 @@ describe("safe artifact output tree", () => {
|
||||
const failure = await tree.rollback().catch((cause: unknown) => cause);
|
||||
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(failure).toMatchObject({
|
||||
cause: { code: "EACCES" },
|
||||
cleanup: { resources: [output] },
|
||||
});
|
||||
} finally {
|
||||
@@ -81,6 +243,54 @@ describe("safe artifact output tree", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
|
||||
"retains cleanup progress when one owned sibling is not writable",
|
||||
async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-siblings-");
|
||||
const output = join(parent, "published");
|
||||
const completed = join(output, "completed");
|
||||
const blocked = join(output, "blocked");
|
||||
const tree = await SafeOutputTree.create(output);
|
||||
for (const directory of ["completed", "blocked"]) {
|
||||
const bytes = Buffer.from(join(output, directory));
|
||||
await tree.write(`${directory}/file.txt`, Readable.from(bytes), {
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.byteLength,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await chmod(blocked, 0o500);
|
||||
const failure = await tree.rollback().catch((cause: unknown) => cause);
|
||||
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(failure).toMatchObject({
|
||||
cause: { code: "EACCES" },
|
||||
cleanup: { resources: [output] },
|
||||
});
|
||||
expect(await readdir(output)).toEqual(["blocked"]);
|
||||
await expect(access(completed)).rejects.toThrow();
|
||||
expect(await readFile(join(blocked, "file.txt"), "utf8")).toBe(blocked);
|
||||
await expect(
|
||||
tree.write("new/file.txt", Readable.from(Buffer.from("late")), {
|
||||
sha256: createHash("sha256").update("late").digest("hex"),
|
||||
bytes: Buffer.byteLength("late"),
|
||||
}),
|
||||
).rejects.toBeInstanceOf(ArtifactReaderFailure);
|
||||
await expect(tree.commit()).rejects.toBeInstanceOf(
|
||||
ArtifactReaderFailure,
|
||||
);
|
||||
} finally {
|
||||
await chmod(blocked, 0o700);
|
||||
}
|
||||
|
||||
expect(await tree.rollback()).toEqual({
|
||||
status: "complete",
|
||||
residualPaths: [],
|
||||
});
|
||||
expect(await readdir(parent)).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it("publishes files while building and preserves them after sealing", async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-");
|
||||
const output = join(parent, "published");
|
||||
@@ -115,6 +325,13 @@ describe("safe artifact output tree", () => {
|
||||
status: "complete",
|
||||
residualPaths: [],
|
||||
});
|
||||
await expect(
|
||||
tree.write("late.txt", Readable.from(Buffer.from("late")), {
|
||||
sha256: createHash("sha256").update("late").digest("hex"),
|
||||
bytes: Buffer.byteLength("late"),
|
||||
}),
|
||||
).rejects.toBeInstanceOf(ArtifactReaderFailure);
|
||||
await expect(tree.commit()).rejects.toBeInstanceOf(ArtifactReaderFailure);
|
||||
});
|
||||
|
||||
it("publishes without POSIX-only directory chmod or fsync on Windows", async () => {
|
||||
|
||||
@@ -187,12 +187,11 @@ describe("canonical skill transaction", () => {
|
||||
expect(installedSkill).toContain(
|
||||
`version: "${PRODUCT_IDENTITY.skillVersion}"`,
|
||||
);
|
||||
expect(installedSkill).toContain("call available analysis tools");
|
||||
expect(installedSkill).toContain("obtain approval before setup writes");
|
||||
expect(await readFile(`${nativeGuide}.rea.backup`, "utf8")).toBe(
|
||||
"stale filesystem-write permission grant\n",
|
||||
);
|
||||
for (const reference of [
|
||||
"connection-and-recovery.md",
|
||||
"native-and-artifacts.md",
|
||||
"javascript-applications.md",
|
||||
"android-applications.md",
|
||||
@@ -243,6 +242,7 @@ describe("canonical skill transaction", () => {
|
||||
const paths = [
|
||||
"SKILL.md",
|
||||
"references/android-applications.md",
|
||||
"references/connection-and-recovery.md",
|
||||
"references/evidence-workflows.md",
|
||||
"references/javascript-applications.md",
|
||||
"references/native-and-artifacts.md",
|
||||
|
||||
Reference in New Issue
Block a user