mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
test(environment): share bundle export inputs (#16115)
This commit is contained in:
1 parent
fdaa06a304
commit
bbb4a949d1
1 file changed
+31
-71
@@ -27,16 +27,21 @@ import {
|
||||
readEnvironmentExportInputs,
|
||||
} from "./environmentExport.js";
|
||||
|
||||
const readBundleInputs = async (root: string) => {
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
return inputs.value;
|
||||
};
|
||||
|
||||
it.each(["replaced", "missing"] as const)(
|
||||
"retains the admitted tarball descriptor when its pathname is %s during output",
|
||||
async (transition) => {
|
||||
const root = await createTestTempDirectory("rea-tarball-instance-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const tarball = join(root, "package.tgz");
|
||||
const originalBytes = Buffer.from("original admitted package");
|
||||
await writeFile(tarball, originalBytes);
|
||||
@@ -60,7 +65,7 @@ it.each(["replaced", "missing"] as const)(
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
packageTarball: tarball,
|
||||
@@ -102,12 +107,7 @@ it.skipIf(process.platform === "win32")(
|
||||
async (context) => {
|
||||
await requirePermissionDenial(context, "directory-write");
|
||||
const root = await createTestTempDirectory("rea-tarball-identity-denied-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const parent = join(root, "packages");
|
||||
const directory = join(root, "bundle");
|
||||
await mkdir(parent);
|
||||
@@ -122,7 +122,7 @@ it.skipIf(process.platform === "win32")(
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
packageTarball: tarball,
|
||||
@@ -157,12 +157,7 @@ it.skipIf(process.platform === "win32")(
|
||||
|
||||
it("keeps tarball ownership when the admitted inode grows during output", async () => {
|
||||
const root = await createTestTempDirectory("rea-tarball-growth-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const tarball = join(root, "package.tgz");
|
||||
await writeFile(tarball, Buffer.alloc(2 * 1024 * 1024, 0x41));
|
||||
const directory = join(root, "bundle");
|
||||
@@ -183,7 +178,7 @@ it("keeps tarball ownership when the admitted inode grows during output", async
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
packageTarball: tarball,
|
||||
@@ -210,12 +205,7 @@ it("keeps tarball ownership when the admitted inode grows during output", async
|
||||
|
||||
it("uses confirmed publication after the output owner's descriptor cleanup completes", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-published-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const directory = join(root, "bundle");
|
||||
const original = SafeOutputTree.prototype.commit;
|
||||
const commit = vi
|
||||
@@ -235,7 +225,7 @@ it("uses confirmed publication after the output owner's descriptor cleanup compl
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
});
|
||||
@@ -243,7 +233,7 @@ it("uses confirmed publication after the output owner's descriptor cleanup compl
|
||||
expect(
|
||||
Buffer.compare(
|
||||
await readFile(join(directory, "envs/grafana-example/evidence.json")),
|
||||
inputs.value.evidence.bytes,
|
||||
inputs.evidence.bytes,
|
||||
),
|
||||
).toBe(0);
|
||||
} finally {
|
||||
@@ -253,19 +243,14 @@ it("uses confirmed publication after the output owner's descriptor cleanup compl
|
||||
|
||||
it("reports a committed bundle when final descriptor cleanup fails", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-cleanup-receipt-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const directory = join(root, "bundle");
|
||||
const close = vi
|
||||
.spyOn(SafeOutputTree.prototype, "closeHandles")
|
||||
.mockRejectedValueOnce(new Error("descriptor close failed"));
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
});
|
||||
@@ -317,12 +302,7 @@ it("reports a committed bundle when final descriptor cleanup fails", async () =>
|
||||
|
||||
it("reports a committed bundle when the admitted tarball cannot close", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-tarball-close-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const directory = join(root, "bundle");
|
||||
const tarball = join(root, "package.tgz");
|
||||
await writeFile(tarball, "selected package");
|
||||
@@ -347,7 +327,7 @@ it("reports a committed bundle when the admitted tarball cannot close", async ()
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
packageTarball: tarball,
|
||||
@@ -383,17 +363,12 @@ it.skipIf(process.platform === "win32")(
|
||||
async (context) => {
|
||||
await requirePermissionDenial(context, "directory-write");
|
||||
const root = await createTestTempDirectory("rea-bundle-readonly-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const directory = join(root, "bundle");
|
||||
await mkdir(directory, { mode: 0o500 });
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
});
|
||||
@@ -422,12 +397,7 @@ it.skipIf(process.platform === "win32")(
|
||||
async (context) => {
|
||||
await requirePermissionDenial(context, "directory-write");
|
||||
const root = await createTestTempDirectory("rea-bundle-later-denied-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const directory = join(root, "bundle");
|
||||
const original = SafeOutputTree.prototype.write;
|
||||
let writes = 0;
|
||||
@@ -441,7 +411,7 @@ it.skipIf(process.platform === "win32")(
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
});
|
||||
@@ -487,12 +457,7 @@ it.each([
|
||||
"reports a later $failure with its own recovery",
|
||||
async ({ failure, error }) => {
|
||||
const root = await createTestTempDirectory("rea-bundle-later-failure-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const directory = join(root, "bundle");
|
||||
const original = SafeOutputTree.prototype.write;
|
||||
const targets: string[] = [];
|
||||
@@ -505,7 +470,7 @@ it.each([
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
});
|
||||
@@ -533,12 +498,7 @@ it
|
||||
"refuses publication after an actual output transition: %s",
|
||||
async (transition) => {
|
||||
const root = await createTestTempDirectory("rea-bundle-output-transition-");
|
||||
const files = await writeEnvironmentServeFiles(root);
|
||||
const inputs = await readEnvironmentExportInputs(
|
||||
files.manifestPath,
|
||||
files.capturePath,
|
||||
);
|
||||
if (!inputs.ok) throw inputs.error;
|
||||
const inputs = await readBundleInputs(root);
|
||||
const directory = join(root, "bundle");
|
||||
const foreign = join(root, "foreign");
|
||||
await mkdir(foreign);
|
||||
@@ -567,7 +527,7 @@ it
|
||||
});
|
||||
try {
|
||||
const result = await exportEnvironmentBundle({
|
||||
...inputs.value,
|
||||
...inputs,
|
||||
source: environmentServeSource(),
|
||||
directory,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user