test(oci): share fixture manifest index updates (#17365)

This commit is contained in:
Vincent Koc
2026-12-06 10:49:34 +08:00
committed by GitHub
parent 06d1cafd2e
commit 3c25661f73
+20 -51
View File
@@ -104,6 +104,20 @@ const readFixtureIndex = async (root: string) => {
return { indexPath, index };
};
const updateFixtureManifestDescriptor = async (
root: string,
digest: string,
manifestJson: string,
) => {
const { indexPath, index } = await readFixtureIndex(root);
index.manifests[0] = {
...index.manifests[0],
digest,
size: Buffer.byteLength(manifestJson),
};
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
};
it("inventories a single-platform layout and keeps Env values by default", async () => {
const root = await createTestTempDirectory("rea-oci-valid-");
const written = await writeOciImageLayoutFixture(root);
@@ -317,13 +331,7 @@ it("recognizes a Docker foreign layer whose blob is absent", async () => {
};
const manifestJson = `${JSON.stringify(manifest)}\n`;
const manifestDigest = await putOciBlob(root, manifestJson);
const { indexPath, index } = await readFixtureIndex(root);
index.manifests[0] = {
...index.manifests[0],
digest: manifestDigest,
size: Buffer.byteLength(manifestJson),
};
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
await updateFixtureManifestDescriptor(root, manifestDigest, manifestJson);
await unlink(join(root, "blobs", parsedLayer.algorithm, parsedLayer.hex));
const report = await inspectLayout(root);
expect(report.images[0]?.layers[0]).toMatchObject({
@@ -840,16 +848,7 @@ it("reports a manifest whose layers is not an array", async () => {
manifest.layers = "not-an-array";
const manifestJson = `${JSON.stringify(manifest)}\n`;
const manifestDigest = await putOciBlob(root, manifestJson);
const indexPath = join(root, "index.json");
const index = JSON.parse(await readFile(indexPath, "utf8")) as {
manifests: { digest: string; size: number }[];
};
index.manifests[0] = {
...index.manifests[0]!,
digest: manifestDigest,
size: Buffer.byteLength(manifestJson),
};
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
await updateFixtureManifestDescriptor(root, manifestDigest, manifestJson);
await unlink(manifestPath);
const report = await inspectLayout(root);
expect(report.findings).toContainEqual(
@@ -885,16 +884,7 @@ it.each([["[]"], ["null"]])(
};
const manifestJson = `${JSON.stringify(manifest)}\n`;
const manifestDigest = await putOciBlob(root, manifestJson);
const indexPath = join(root, "index.json");
const index = JSON.parse(await readFile(indexPath, "utf8")) as {
manifests: { digest: string; size: number }[];
};
index.manifests[0] = {
...index.manifests[0]!,
digest: manifestDigest,
size: Buffer.byteLength(manifestJson),
};
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
await updateFixtureManifestDescriptor(root, manifestDigest, manifestJson);
await unlink(manifestPath);
const report = await inspectLayout(root);
expect(report.findings).toContainEqual(
@@ -1790,16 +1780,7 @@ const writeSha1LayerLayout = async (root: string, declaredSize: number) => {
});
const manifestJson = `${JSON.stringify(manifest)}\n`;
const manifestDigest = await putOciBlob(root, manifestJson);
const indexPath = join(root, "index.json");
const index = JSON.parse(await readFile(indexPath, "utf8")) as {
manifests: { digest: string; size: number }[];
};
index.manifests[0] = {
...index.manifests[0]!,
digest: manifestDigest,
size: Buffer.byteLength(manifestJson),
};
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
await updateFixtureManifestDescriptor(root, manifestDigest, manifestJson);
await unlink(manifestPath);
return { hex, digest };
};
@@ -3310,13 +3291,7 @@ const writeLayoutWithConfigPatch = async (
const manifestJson = `${JSON.stringify(manifest)}\n`;
await unlink(oldManifestPath);
const manifestDigest = await putOciBlob(root, manifestJson);
const { indexPath, index } = await readFixtureIndex(root);
index.manifests[0] = {
...index.manifests[0],
digest: manifestDigest,
size: Buffer.byteLength(manifestJson),
};
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
await updateFixtureManifestDescriptor(root, manifestDigest, manifestJson);
return { ...written, manifestDigest, configDigest };
};
@@ -3737,13 +3712,7 @@ const rewriteManifestDocument = async (
const manifestJson = `${JSON.stringify(manifest)}\n`;
const digest = await putOciBlob(root, manifestJson);
await unlink(join(root, "blobs", "sha256", hex ?? ""));
const { indexPath, index } = await readFixtureIndex(root);
index.manifests[0] = {
...index.manifests[0],
digest,
size: Buffer.byteLength(manifestJson),
};
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
await updateFixtureManifestDescriptor(root, digest, manifestJson);
return digest;
};