Pin established artwork provenance and persist pre-upload backups
This commit is contained in:
parent
61be734999
commit
1684b3064d
9 changed files with 391 additions and 31 deletions
|
|
@ -1310,9 +1310,16 @@ node web-client/scripts/publish-achievement-assets.mjs # offline dry run only
|
|||
|
||||
The source/integrity manifest is `release/achievement-assets.json`; generated
|
||||
256px PNGs, a light/dark contact sheet and their SHA-256 receipt remain ignored
|
||||
under `.engine/achievement-assets/`. Four legacy PNG provenance records still
|
||||
require exact-source/license verification; do not treat repository inclusion as
|
||||
proof of third-party licensing. Lucide notices are included verbatim.
|
||||
under `.engine/achievement-assets/`. Four legacy PNGs use the explicitly authorized
|
||||
`verified-existing-project-asset` route, pinned to source paths/hashes, import
|
||||
commits and identical production-use evidence. Their per-item licenses remain
|
||||
unverified; neither CC0 nor blanket MIT is asserted. Lucide notices are included
|
||||
verbatim. The guard permits only these four established identities through this route.
|
||||
|
||||
Before any PUT, original metadata and version snapshots must be durably saved in
|
||||
unique 0700 `.engine/releases/achievement-assets/run-*` directories with 0600 files.
|
||||
The per-run receipt references backup paths/hashes, never credentials. Persistence
|
||||
failure stops uploads; retries preserve previous originals. No broad restore is provided.
|
||||
|
||||
After the code, provenance and exact artwork receipt have independent approval,
|
||||
upload named assets through the dedicated helper with its explicit publish flag
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
"check": "svelte-check --tsconfig ./tsconfig.json",
|
||||
"test": "node --experimental-strip-types --test src/*.test.ts && node --test scripts/publish-gallery.test.mjs && npm run test:achievement-assets && npm run test:locales",
|
||||
"build:achievement-assets": "node scripts/build-achievement-assets.mjs",
|
||||
"test:achievement-assets": "node --test scripts/achievement-assets.test.mjs scripts/publish-achievement-assets.test.mjs",
|
||||
"test:achievement-assets": "node --test scripts/achievement-assets.test.mjs scripts/publish-achievement-assets.test.mjs scripts/publish-achievement-backups.test.mjs",
|
||||
"build:bridge": "bash scripts/build-bridge.sh",
|
||||
"publish:bgs": "node scripts/publish.mjs",
|
||||
"test:locales": "node ../scripts/check-locales.mjs src/localization && node --test scripts/localization-source.test.mjs && npm run localization:check",
|
||||
|
|
|
|||
|
|
@ -27,9 +27,18 @@
|
|||
"path": "client/assets/colosseum-rome-svgrepo-com.png",
|
||||
"sha256": "660f60ac288e2ed97ae208fce824ec4b39681008b68429b82b76f9dfeefb6d67",
|
||||
"provenance": {
|
||||
"type": "verified-existing-project-asset",
|
||||
"license": null,
|
||||
"status": "unresolved — provenance investigation pending; no publication approval",
|
||||
"originalPath": "client/assets/colosseum-rome-svgrepo-com.png"
|
||||
"licenseStatus": "per-item-license-unverified",
|
||||
"sourcePath": "client/assets/colosseum-rome-svgrepo-com.png",
|
||||
"sourceSha256": "660f60ac288e2ed97ae208fce824ec4b39681008b68429b82b76f9dfeefb6d67",
|
||||
"historicalCommit": "603be9b8f0a361bebcef69d019c6451d75255eb8",
|
||||
"existingUse": {
|
||||
"viewerUrl": "https://s3.fr-par.scw.cloud/bgs-assets/games/clash/1/viewer/assets-890e8364e4f3fe49236b/viewer.js",
|
||||
"embeddedPngSha256": "660f60ac288e2ed97ae208fce824ec4b39681008b68429b82b76f9dfeefb6d67",
|
||||
"evidence": "Original commit bytes and current production viewer embedded PNG bytes exactly match this source hash; canonical faction mapping uses this PNG. Import PR #233."
|
||||
},
|
||||
"authorization": "explicit-user-request-to-reuse-established-project-artwork"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -41,9 +50,18 @@
|
|||
"path": "client/assets/temple-building-with-columns-svgrepo-com.png",
|
||||
"sha256": "939ab2c36bb3f29aa066348f5ea0f8418e76442f1fcae1537a27ec1706a57e0f",
|
||||
"provenance": {
|
||||
"type": "verified-existing-project-asset",
|
||||
"license": null,
|
||||
"status": "unresolved — provenance investigation pending; no publication approval",
|
||||
"originalPath": "client/assets/temple-building-with-columns-svgrepo-com.png"
|
||||
"licenseStatus": "per-item-license-unverified",
|
||||
"sourcePath": "client/assets/temple-building-with-columns-svgrepo-com.png",
|
||||
"sourceSha256": "939ab2c36bb3f29aa066348f5ea0f8418e76442f1fcae1537a27ec1706a57e0f",
|
||||
"historicalCommit": "7fc48ab4187c9d8bb874b11ec2581ce1b4a1fc97",
|
||||
"existingUse": {
|
||||
"viewerUrl": "https://s3.fr-par.scw.cloud/bgs-assets/games/clash/1/viewer/assets-890e8364e4f3fe49236b/viewer.js",
|
||||
"embeddedPngSha256": "939ab2c36bb3f29aa066348f5ea0f8418e76442f1fcae1537a27ec1706a57e0f",
|
||||
"evidence": "Original commit bytes and current production viewer embedded PNG bytes exactly match this source hash; canonical faction mapping uses this PNG. Import PR #97."
|
||||
},
|
||||
"authorization": "explicit-user-request-to-reuse-established-project-artwork"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -55,9 +73,18 @@
|
|||
"path": "client/assets/great-wall-of-china-chinese-svgrepo-com.png",
|
||||
"sha256": "edc3bfe45c937482fedb708bcd794ed589241f96b095a55daa25be7bb4656e3c",
|
||||
"provenance": {
|
||||
"type": "verified-existing-project-asset",
|
||||
"license": null,
|
||||
"status": "unresolved — provenance investigation pending; no publication approval",
|
||||
"originalPath": "client/assets/great-wall-of-china-chinese-svgrepo-com.png"
|
||||
"licenseStatus": "per-item-license-unverified",
|
||||
"sourcePath": "client/assets/great-wall-of-china-chinese-svgrepo-com.png",
|
||||
"sourceSha256": "edc3bfe45c937482fedb708bcd794ed589241f96b095a55daa25be7bb4656e3c",
|
||||
"historicalCommit": "603be9b8f0a361bebcef69d019c6451d75255eb8",
|
||||
"existingUse": {
|
||||
"viewerUrl": "https://s3.fr-par.scw.cloud/bgs-assets/games/clash/1/viewer/assets-890e8364e4f3fe49236b/viewer.js",
|
||||
"embeddedPngSha256": "edc3bfe45c937482fedb708bcd794ed589241f96b095a55daa25be7bb4656e3c",
|
||||
"evidence": "Original commit bytes and current production viewer embedded PNG bytes exactly match this source hash; canonical faction mapping uses this PNG. Import PR #233."
|
||||
},
|
||||
"authorization": "explicit-user-request-to-reuse-established-project-artwork"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -69,9 +96,18 @@
|
|||
"path": "client/assets/viking-ship-svgrepo-com.png",
|
||||
"sha256": "a195e2fcafbb2338a6b79c05f55f6c3e5aa64fd68352c30f82e13b8d9094274b",
|
||||
"provenance": {
|
||||
"type": "verified-existing-project-asset",
|
||||
"license": null,
|
||||
"status": "unresolved — provenance investigation pending; no publication approval",
|
||||
"originalPath": "client/assets/viking-ship-svgrepo-com.png"
|
||||
"licenseStatus": "per-item-license-unverified",
|
||||
"sourcePath": "client/assets/viking-ship-svgrepo-com.png",
|
||||
"sourceSha256": "a195e2fcafbb2338a6b79c05f55f6c3e5aa64fd68352c30f82e13b8d9094274b",
|
||||
"historicalCommit": "77bfc205eec2b664b24846753e0680ebf6ec9740",
|
||||
"existingUse": {
|
||||
"viewerUrl": "https://s3.fr-par.scw.cloud/bgs-assets/games/clash/1/viewer/assets-890e8364e4f3fe49236b/viewer.js",
|
||||
"embeddedPngSha256": "a195e2fcafbb2338a6b79c05f55f6c3e5aa64fd68352c30f82e13b8d9094274b",
|
||||
"evidence": "Original commit bytes and current production viewer embedded PNG bytes exactly match this source hash; canonical faction mapping uses this PNG. Import PR #265."
|
||||
},
|
||||
"authorization": "explicit-user-request-to-reuse-established-project-artwork"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ change: inspect the changes, review provenance, and deliberately update hashes.
|
|||
A successful local build is **not** artwork approval or permission to publish.
|
||||
No uploads are performed by these tools.
|
||||
|
||||
## Attribution and unresolved provenance
|
||||
## Attribution and established project reuse
|
||||
|
||||
The eleven Lucide symbols come from `lucide-svelte` **0.577.0**,
|
||||
https://github.com/lucide-icons/lucide. The full package license is copied verbatim
|
||||
|
|
@ -55,8 +55,22 @@ portions. Preserve these notices with distributions of the derived artwork.
|
|||
|
||||
Rome, Greece, China, and Vikings reuse the repository's original PNG assets in
|
||||
`client/assets/` (exact original paths and SHA-256 hashes are in the manifest).
|
||||
Their upstream authorship, original download locations, and applicable licenses
|
||||
are **still under investigation**. Filenames mentioning SVG Repo are not adequate
|
||||
license evidence. This document does **not** assert that the repository's root
|
||||
MIT license covers these PNGs. Publication remains blocked pending documented
|
||||
provenance/license review and independent visual review of the contact sheet.
|
||||
The user explicitly authorized reuse of this established project artwork after
|
||||
confirmation that the original import bytes and currently served viewer PNGs match.
|
||||
The manifest records source paths/hashes, historical commits and production-use
|
||||
evidence as `verified-existing-project-asset`. The publisher accepts only these four
|
||||
pinned identities through this path; it is not an arbitrary missing-license bypass.
|
||||
Per-item licenses remain **unverified** (`license: null`); no CC0 or blanket root-MIT
|
||||
coverage is claimed. No known restriction was found in the bounded investigation.
|
||||
Independent review of the final delta and exact artwork receipt remains required.
|
||||
|
||||
## Durable publication backups
|
||||
|
||||
Before any PUT, the publisher saves original metadata and version snapshots under
|
||||
`.engine/releases/achievement-assets/run-*`. Each run has a unique 0700 directory,
|
||||
exclusive-created 0600 snapshots, and fsynced files/directories. Failure to persist
|
||||
backups or the initial receipt stops uploads. Retries never overwrite prior runs.
|
||||
The per-run `upload-receipt.json` references snapshot paths and SHA-256 hashes;
|
||||
credentials/request headers are not included. Preserve these records if an upload
|
||||
fails. Recovery is manual and limited to affected named assets after inspection;
|
||||
this tool deliberately provides no broad metadata restore operation.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ The actual existing PNG masks remain the inputs. Their hashes are pinned in
|
|||
SVG Repo item-page metadata identifies the candidates below, but the original
|
||||
SVG image requests were blocked or failed to render during verification. A page
|
||||
name or license label does not prove its image matches a local PNG. **None of
|
||||
these candidate matches is currently cleared for new publication.**
|
||||
these candidate matches establishes a license for the local PNGs.**
|
||||
|
||||
| Existing symbol | Candidate item pages | Observed page license/provider |
|
||||
| --- | --- | --- |
|
||||
|
|
@ -32,5 +32,29 @@ Local silhouettes to match against actual licensed originals:
|
|||
|
||||
The Greek candidate page's license was additionally confirmed via a rendered page
|
||||
capture, but its main artwork was a broken image. Do not treat that capture as a
|
||||
successful visual match. Exact item IDs, image correspondence evidence and relevant
|
||||
license/attribution terms must be reviewed before clearing the manifest records.
|
||||
successful visual match. Exact correspondence and license terms remain unverified.
|
||||
|
||||
## Accepted existing-project reuse basis
|
||||
|
||||
The user explicitly accepted reuse of the established project artwork. This is not
|
||||
an assertion of per-item CC0 or root-MIT coverage. A bounded repository attribution
|
||||
and import-history check found no known restriction, but no per-image license
|
||||
record either; importing PR bodies are empty.
|
||||
|
||||
Original paths and complete hashes/commits are recorded in the manifest:
|
||||
|
||||
- Rome and China: imported by `603be9b8f0a361bebcef69d019c6451d75255eb8`, PR #233 (2025-04-30).
|
||||
- Greece: imported by `7fc48ab4187c9d8bb874b11ec2581ce1b4a1fc97`, PR #97 (2025-01-02).
|
||||
- Vikings: imported by `77bfc205eec2b664b24846753e0680ebf6ec9740`, PR #265 (2025-06-09).
|
||||
|
||||
`git show <commit>:<sourcePath>` bytes matched the current pinned source hashes.
|
||||
A read-only download of the production viewer URL recorded in each manifest entry
|
||||
confirmed that all four exact PNG byte sequences are embedded in that bundle.
|
||||
`web-client/src/civilization-emblems.ts` uses them for these same factions; the
|
||||
native client also references the source files. The named-asset registry contains
|
||||
only a pictogram and screenshots, not reusable faction entries.
|
||||
|
||||
The scoped publisher guard accepts these four pinned identities as
|
||||
`verified-existing-project-asset`, with explicit `per-item-license-unverified`
|
||||
status and user authorization. Missing metadata is not treated as a prohibition.
|
||||
Other assets cannot use this path without a separately reviewed code change.
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ if (process.argv.includes('--check')) {
|
|||
`<figure><img src="data:image/png;base64,${first[i].data}"><figcaption>${a.civilization}<br><small>${a.key}</small></figcaption></figure>`,
|
||||
)
|
||||
.join('');
|
||||
const html = `<!doctype html><meta charset="utf-8"><title>Achievement artwork review — local only</title><style>body{font:16px sans-serif;margin:24px;background:#fff;color:#18212b}section{display:grid;grid-template-columns:repeat(5,1fr);gap:16px;padding:16px}figure{margin:0;text-align:center}img{width:192px;height:192px}figcaption{padding:8px}small{font-size:11px}.dark{background:#18212b;color:#fff}</style><h1>Local achievement artwork review</h1><p>15 canonical symbols. PNG provenance unresolved; not publication approval.</p><section>${cards}</section><h2>Dark surround</h2><section class="dark">${cards}</section>`;
|
||||
const html = `<!doctype html><meta charset="utf-8"><title>Achievement artwork review — local only</title><style>body{font:16px sans-serif;margin:24px;background:#fff;color:#18212b}section{display:grid;grid-template-columns:repeat(5,1fr);gap:16px;padding:16px}figure{margin:0;text-align:center}img{width:192px;height:192px}figcaption{padding:8px}small{font-size:11px}.dark{background:#18212b;color:#fff}</style><h1>Local achievement artwork review</h1><p>15 canonical symbols. Established project PNG reuse; per-item licenses unverified. Final review required.</p><section>${cards}</section><h2>Dark surround</h2><section class="dark">${cards}</section>`;
|
||||
await writeFile(path.join(outputDir, 'contact-sheet.html'), html);
|
||||
await page.setContent(html);
|
||||
await page.screenshot({ path: path.join(outputDir, 'contact-sheet.png'), fullPage: true });
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Offline by default. This tool only writes named assets, never game metadata,
|
||||
// gallery, engine releases, activation, or viewer configuration.
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile, writeFile } from 'node:fs/promises';
|
||||
import { readFile, mkdir, mkdtemp, chmod, open, rename, rmdir } from 'node:fs/promises';
|
||||
import { homedir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
|
@ -22,8 +22,35 @@ function httpsUrl(value) {
|
|||
}
|
||||
}
|
||||
|
||||
// License clearance is a human review, not inferred from a filename or an icon
|
||||
// site's general license. PNG provenance must contain:
|
||||
// Narrow, user-authorized reuse of the exact four symbols already served by Clash.
|
||||
// These pins establish project identity/history, NOT per-item license clearance.
|
||||
const existingProjectPngs = {
|
||||
'achievement-faction-rome': [
|
||||
'client/assets/colosseum-rome-svgrepo-com.png',
|
||||
'660f60ac288e2ed97ae208fce824ec4b39681008b68429b82b76f9dfeefb6d67',
|
||||
'603be9b8f0a361bebcef69d019c6451d75255eb8',
|
||||
],
|
||||
'achievement-faction-greece': [
|
||||
'client/assets/temple-building-with-columns-svgrepo-com.png',
|
||||
'939ab2c36bb3f29aa066348f5ea0f8418e76442f1fcae1537a27ec1706a57e0f',
|
||||
'7fc48ab4187c9d8bb874b11ec2581ce1b4a1fc97',
|
||||
],
|
||||
'achievement-faction-china': [
|
||||
'client/assets/great-wall-of-china-chinese-svgrepo-com.png',
|
||||
'edc3bfe45c937482fedb708bcd794ed589241f96b095a55daa25be7bb4656e3c',
|
||||
'603be9b8f0a361bebcef69d019c6451d75255eb8',
|
||||
],
|
||||
'achievement-faction-vikings': [
|
||||
'client/assets/viking-ship-svgrepo-com.png',
|
||||
'a195e2fcafbb2338a6b79c05f55f6c3e5aa64fd68352c30f82e13b8d9094274b',
|
||||
'77bfc205eec2b664b24846753e0680ebf6ec9740',
|
||||
],
|
||||
};
|
||||
const existingViewer =
|
||||
'https://s3.fr-par.scw.cloud/bgs-assets/games/clash/1/viewer/assets-890e8364e4f3fe49236b/viewer.js';
|
||||
|
||||
// Other PNGs still need matched source/license evidence, not a filename or a
|
||||
// site's general license. Their provenance must contain:
|
||||
// license: nonempty license identifier/text; sourceUrl: exact HTTPS artwork URL;
|
||||
// verification: { sourceUrl, sourceSha256, license, evidence }.
|
||||
// The first three verification fields must match this source exactly; evidence
|
||||
|
|
@ -33,6 +60,24 @@ export function licenseBlockers(manifest) {
|
|||
return manifest.assets.flatMap(({ key, source }) => {
|
||||
const p = source.provenance ?? {};
|
||||
const errors = [];
|
||||
if (p.type === 'verified-existing-project-asset') {
|
||||
const pin = existingProjectPngs[key];
|
||||
const valid =
|
||||
source.type === 'png' &&
|
||||
pin &&
|
||||
source.path === pin[0] &&
|
||||
source.sha256 === pin[1] &&
|
||||
p.sourcePath === pin[0] &&
|
||||
p.sourceSha256 === pin[1] &&
|
||||
p.historicalCommit === pin[2] &&
|
||||
p.license === null &&
|
||||
p.licenseStatus === 'per-item-license-unverified' &&
|
||||
p.existingUse?.viewerUrl === existingViewer &&
|
||||
p.existingUse?.embeddedPngSha256 === pin[1] &&
|
||||
nonempty(p.existingUse?.evidence) &&
|
||||
p.authorization === 'explicit-user-request-to-reuse-established-project-artwork';
|
||||
return valid ? [] : [{ key, reason: 'invalid verified existing project asset evidence' }];
|
||||
}
|
||||
if (!nonempty(p.license)) errors.push('missing license');
|
||||
if (source.type === 'png') {
|
||||
if (!httpsUrl(p.sourceUrl)) errors.push('missing unsigned HTTPS sourceUrl');
|
||||
|
|
@ -114,6 +159,59 @@ async function loadLocal() {
|
|||
return { manifest, receipt, receiptBytes, files };
|
||||
}
|
||||
|
||||
async function syncDirectory(directory) {
|
||||
const handle = await open(directory, 'r');
|
||||
try {
|
||||
await handle.sync();
|
||||
} finally {
|
||||
await handle.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function writeExclusive(file, bytes) {
|
||||
const handle = await open(file, 'wx', 0o600);
|
||||
try {
|
||||
await handle.chmod(0o600);
|
||||
await handle.writeFile(bytes);
|
||||
await handle.sync();
|
||||
} finally {
|
||||
await handle.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Only the two source JSON responses belong here: never request options or credentials.
|
||||
// Each attempt gets a new directory; even failed attempts retain their originals.
|
||||
export async function persistBackup(
|
||||
{ meta, version },
|
||||
baseDirectory = path.join(path.dirname(outputDir), 'releases', 'achievement-assets'),
|
||||
) {
|
||||
await mkdir(baseDirectory, { recursive: true, mode: 0o700 });
|
||||
const directory = await mkdtemp(path.join(baseDirectory, 'run-'));
|
||||
await chmod(directory, 0o700);
|
||||
const result = { directory, receiptPath: path.join(directory, 'upload-receipt.json') };
|
||||
for (const [name, value] of Object.entries({ meta, version })) {
|
||||
const bytes = Buffer.from(JSON.stringify(value, null, 2) + '\n');
|
||||
const file = path.join(directory, `${name}.json`);
|
||||
await writeExclusive(file, bytes);
|
||||
result[name] = { path: file, sha256: sha256(bytes) };
|
||||
}
|
||||
await syncDirectory(directory);
|
||||
await syncDirectory(baseDirectory);
|
||||
await syncDirectory(path.dirname(baseDirectory));
|
||||
return result;
|
||||
}
|
||||
|
||||
async function saveBackupReceipt(backup, data) {
|
||||
// Exclusive temporary file + rename keeps the previous receipt intact on failure.
|
||||
const temporary = await mkdtemp(path.join(backup.directory, '.receipt-'));
|
||||
await chmod(temporary, 0o700);
|
||||
const file = path.join(temporary, 'receipt.json');
|
||||
await writeExclusive(file, JSON.stringify(data, null, 2) + '\n');
|
||||
await rename(file, backup.receiptPath);
|
||||
await rmdir(temporary);
|
||||
await syncDirectory(backup.directory);
|
||||
}
|
||||
|
||||
export async function run(args = [], dependencies = {}) {
|
||||
assert.ok(
|
||||
args.every((a) => a === '--publish' || a === '--dry-run' || /^--reviewed-sha256=[a-f0-9]{64}$/.test(a)),
|
||||
|
|
@ -147,12 +245,7 @@ export async function run(args = [], dependencies = {}) {
|
|||
).trim();
|
||||
assert.ok(token.length > 0, 'Missing admin token');
|
||||
const fetcher = dependencies.fetch ?? globalThis.fetch;
|
||||
const save =
|
||||
dependencies.save ??
|
||||
((data) =>
|
||||
writeFile(path.join(outputDir, 'upload-receipt.json'), JSON.stringify(data, null, 2) + '\n', {
|
||||
mode: 0o600,
|
||||
}));
|
||||
|
||||
// Never echo remote bodies, errors, headers, or tokens (including fetch errors).
|
||||
try {
|
||||
async function request(url, options = {}) {
|
||||
|
|
@ -175,11 +268,14 @@ export async function run(args = [], dependencies = {}) {
|
|||
}
|
||||
const before = await api('/gameinfo/clash/meta');
|
||||
const gameBefore = await api('/gameinfo/clash/1');
|
||||
const backup = await (dependencies.persistBackup ?? persistBackup)({ meta: before, version: gameBefore });
|
||||
const save = dependencies.save ?? ((data) => saveBackupReceipt(backup, data));
|
||||
const uploads = [];
|
||||
const evidence = {
|
||||
formatRevision: 1,
|
||||
achievementRevision: receipt.revision,
|
||||
reviewedReceiptSha256: reviewedSha256,
|
||||
backup,
|
||||
assets: uploads,
|
||||
status: 'incomplete',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import {
|
||||
run,
|
||||
licenseBlockers,
|
||||
|
|
@ -86,6 +87,58 @@ test('PNG clearance requires source URL, exact license/source hash match, and ev
|
|||
}
|
||||
});
|
||||
|
||||
test('only the four pinned existing project PNGs qualify without a per-item license claim', async () => {
|
||||
const manifest = JSON.parse(
|
||||
await readFile(new URL('../release/achievement-assets.json', import.meta.url), 'utf8'),
|
||||
);
|
||||
assert.deepEqual(licenseBlockers(manifest), []);
|
||||
const assets = manifest.assets.filter((a) => a.source.type === 'png');
|
||||
assert.equal(assets.length, 4);
|
||||
for (const asset of assets) {
|
||||
assert.equal(asset.source.provenance.license, null);
|
||||
for (const field of [
|
||||
'sourcePath',
|
||||
'sourceSha256',
|
||||
'historicalCommit',
|
||||
'licenseStatus',
|
||||
'authorization',
|
||||
]) {
|
||||
const changed = structuredClone(asset);
|
||||
changed.source.provenance[field] = 'invalid';
|
||||
assert.ok(licenseBlockers({ assets: [changed] }).length, field);
|
||||
}
|
||||
for (const field of ['viewerUrl', 'embeddedPngSha256', 'evidence']) {
|
||||
const changed = structuredClone(asset);
|
||||
changed.source.provenance.existingUse[field] = '';
|
||||
assert.ok(licenseBlockers({ assets: [changed] }).length, field);
|
||||
}
|
||||
for (const mutate of [
|
||||
(a) => {
|
||||
a.key = 'achievement-faction-arbitrary';
|
||||
},
|
||||
(a) => {
|
||||
a.source.path = 'other.png';
|
||||
},
|
||||
(a) => {
|
||||
a.source.sha256 = '0'.repeat(64);
|
||||
},
|
||||
(a) => {
|
||||
a.source.type = 'lucide';
|
||||
},
|
||||
(a) => {
|
||||
a.source.provenance.license = 'CC0';
|
||||
},
|
||||
(a) => {
|
||||
delete a.source.provenance;
|
||||
},
|
||||
]) {
|
||||
const changed = structuredClone(asset);
|
||||
mutate(changed);
|
||||
assert.ok(licenseBlockers({ assets: [changed] }).length);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('review rejects changed receipt, unexpected key and invalid dimensions', () => {
|
||||
const local = fixture();
|
||||
const validate = () =>
|
||||
|
|
@ -164,6 +217,12 @@ function mockPublication(local, mutate = () => {}) {
|
|||
const deps = {
|
||||
loadLocal: async () => local,
|
||||
readToken: async () => 'SECRET-DO-NOT-LOG',
|
||||
persistBackup: async () => ({
|
||||
directory: '/mock/run-unique',
|
||||
receiptPath: '/mock/run-unique/upload-receipt.json',
|
||||
meta: { path: '/mock/run-unique/meta.json', sha256: '1'.repeat(64) },
|
||||
version: { path: '/mock/run-unique/version.json', sha256: '2'.repeat(64) },
|
||||
}),
|
||||
save: async (value) => saved.push(structuredClone(value)),
|
||||
fetch: async (url, options) => {
|
||||
calls.push({ url, options });
|
||||
|
|
|
|||
124
web-client/scripts/publish-achievement-backups.test.mjs
Normal file
124
web-client/scripts/publish-achievement-backups.test.mjs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { persistBackup, run } from './publish-achievement-assets.mjs';
|
||||
import { sha256 } from './achievement-asset-inputs.mjs';
|
||||
|
||||
async function temporary(t) {
|
||||
const directory = await mkdtemp(path.join(tmpdir(), 'achievement-backups-'));
|
||||
t.after(() => rm(directory, { recursive: true, force: true }));
|
||||
return directory;
|
||||
}
|
||||
|
||||
test('real backups are private, unique across retries, and retain original snapshot bytes/hashes', async (t) => {
|
||||
const base = path.join(await temporary(t), 'releases', 'achievement-assets');
|
||||
const original = { meta: { gallery: ['original'], assets: {} }, version: { version: 1, assets: {} } };
|
||||
const first = await persistBackup(original, base);
|
||||
const bytes = {};
|
||||
assert.equal((await stat(first.directory)).mode & 0o777, 0o700);
|
||||
assert.match(path.basename(first.directory), /^run-/);
|
||||
assert.equal(first.receiptPath, path.join(first.directory, 'upload-receipt.json'));
|
||||
for (const name of ['meta', 'version']) {
|
||||
bytes[name] = await readFile(first[name].path);
|
||||
assert.equal((await stat(first[name].path)).mode & 0o777, 0o600);
|
||||
assert.deepEqual(JSON.parse(bytes[name]), original[name]);
|
||||
assert.equal(sha256(bytes[name]), first[name].sha256);
|
||||
}
|
||||
original.meta.assets.changed = { url: 'new' };
|
||||
const second = await persistBackup(original, base);
|
||||
assert.notEqual(first.directory, second.directory);
|
||||
for (const name of ['meta', 'version']) {
|
||||
assert.deepEqual(await readFile(first[name].path), bytes[name]);
|
||||
assert.equal(sha256(await readFile(first[name].path)), first[name].sha256);
|
||||
}
|
||||
assert.notEqual(first.meta.sha256, second.meta.sha256);
|
||||
});
|
||||
|
||||
test('real backup persistence rejects an unusable destination', async (t) => {
|
||||
const file = path.join(await temporary(t), 'not-a-directory');
|
||||
await writeFile(file, 'preserve');
|
||||
await assert.rejects(persistBackup({ meta: {}, version: {} }, file));
|
||||
assert.equal(await readFile(file, 'utf8'), 'preserve');
|
||||
});
|
||||
|
||||
function fixture() {
|
||||
const key = 'achievement-faction-rome';
|
||||
const png = Buffer.from('frozen fixture');
|
||||
const manifest = {
|
||||
assets: [
|
||||
{
|
||||
key,
|
||||
civilization: 'Rome',
|
||||
source: { type: 'lucide', sha256: sha256(png), provenance: { license: 'ISC' } },
|
||||
},
|
||||
],
|
||||
};
|
||||
const receipt = {
|
||||
revision: 2,
|
||||
assets: [{ key, civilization: 'Rome', file: `${key}.png`, sha256: sha256(png), width: 256, height: 256 }],
|
||||
};
|
||||
return {
|
||||
manifest,
|
||||
receipt,
|
||||
receiptBytes: Buffer.from(JSON.stringify(receipt)),
|
||||
files: new Map([[key, png]]),
|
||||
};
|
||||
}
|
||||
|
||||
for (const failure of ['none', 'backup', 'save']) {
|
||||
test(`publication awaits backup and initial receipt before PUT (${failure})`, async () => {
|
||||
const local = fixture();
|
||||
const events = [];
|
||||
const meta = { gallery: ['original'] };
|
||||
const version = { version: 1 };
|
||||
const backup = {
|
||||
directory: '/private/run-test',
|
||||
receiptPath: '/private/run-test/upload-receipt.json',
|
||||
meta: { path: '/private/run-test/meta.json', sha256: 'a'.repeat(64) },
|
||||
version: { path: '/private/run-test/version.json', sha256: 'b'.repeat(64) },
|
||||
};
|
||||
let saved;
|
||||
await assert.rejects(
|
||||
run(['--publish', `--reviewed-sha256=${sha256(local.receiptBytes)}`], {
|
||||
loadLocal: async () => local,
|
||||
readToken: async () => 'secret-test-token',
|
||||
fetch: async (url, options) => {
|
||||
if (options.method === 'PUT') {
|
||||
events.push('PUT');
|
||||
throw Error('Stop after observing first PUT; no network');
|
||||
}
|
||||
events.push(url.endsWith('/meta') ? 'GET meta' : 'GET version');
|
||||
return { ok: true, json: async () => (url.endsWith('/meta') ? meta : version) };
|
||||
},
|
||||
persistBackup: async (sources) => {
|
||||
assert.deepEqual(sources, { meta, version });
|
||||
events.push('backup start');
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
if (failure === 'backup') throw Error('disk failure');
|
||||
events.push('backup complete');
|
||||
return backup;
|
||||
},
|
||||
save: async (evidence) => {
|
||||
events.push('save start');
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
if (failure === 'save') throw Error('receipt failure');
|
||||
saved = structuredClone(evidence);
|
||||
events.push('save complete');
|
||||
},
|
||||
}),
|
||||
/Publication\/verification failed/,
|
||||
);
|
||||
const expected = ['GET meta', 'GET version', 'backup start'];
|
||||
if (failure !== 'backup') expected.push('backup complete', 'save start');
|
||||
if (failure === 'none') expected.push('save complete', 'PUT');
|
||||
assert.deepEqual(events, expected);
|
||||
if (saved) {
|
||||
assert.deepEqual(saved.backup, backup);
|
||||
assert.equal(saved.status, 'incomplete');
|
||||
assert.ok(!JSON.stringify(saved).includes('secret-test-token'));
|
||||
assert.ok(!JSON.stringify(saved).includes('Authorization'));
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue