38 lines
2.6 KiB
JavaScript
38 lines
2.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {mkdtempSync,readFileSync,mkdirSync,writeFileSync} from 'node:fs';
|
|
import {tmpdir} from 'node:os';
|
|
import path from 'node:path';
|
|
import {createHash} from 'node:crypto';
|
|
import {packageDeploymentScripts} from '../scripts/deployment-package.mjs';
|
|
|
|
test('built operational scripts have deterministic bytes, exact hashes and recorded source identity',()=>{
|
|
const folder=mkdtempSync(path.join(tmpdir(),'dune-web-deployment-')),source=path.join(folder,'source'),output=path.join(folder,'output');mkdirSync(source);
|
|
for(const name of ['dunerealms-ci-trigger','dunerealms-build-release','configure-lobby-account.py'])writeFileSync(path.join(source,name),'#!/bin/bash\r\necho verified\r\n');
|
|
const commit='a'.repeat(40),manifest=packageDeploymentScripts(output,commit,{sourceDirectory:source});
|
|
assert.equal(manifest.sourceCommit,commit);assert.equal(manifest.sourceRepository,'https://www.dunerealms.com/git/unimatrix/web.git');
|
|
for(const [name,record] of Object.entries(manifest.files)){
|
|
const bytes=readFileSync(path.join(output,name));assert.equal(bytes.toString(),'#!/bin/bash\necho verified\n');
|
|
assert.equal(record.bytes,bytes.length);assert.equal(record.sha256,createHash('sha256').update(bytes).digest('hex'));
|
|
}
|
|
assert.deepEqual(JSON.parse(readFileSync(path.join(output,'manifest.json'))),manifest);
|
|
assert.throws(()=>packageDeploymentScripts(output,'../main',{sourceDirectory:source}),/Invalid deployment source commit/);
|
|
});
|
|
|
|
test('website trigger and builder fetch only canonical web main even when checkout origin differs',()=>{
|
|
for(const name of ['dunerealms-ci-trigger','dunerealms-build-release']){
|
|
const source=readFileSync(new URL('../ops/'+name,import.meta.url),'utf8');
|
|
assert.match(source,/^SOURCE_URL=https:\/\/www\.dunerealms\.com\/git\/unimatrix\/web\.git\r?$/m);
|
|
assert.match(source,/git (?:-C "\$REPO" )?fetch -q "\$SOURCE_URL" refs\/heads\/main/);
|
|
assert.doesNotMatch(source,/git .*fetch -q origin/);
|
|
assert.match(source,/rev-parse FETCH_HEAD/);
|
|
}
|
|
});
|
|
|
|
test('staging archive retains the repository-policy inputs used by the full website suite',()=>{
|
|
const source=readFileSync(new URL('../ops/dunerealms-build-release',import.meta.url),'utf8');
|
|
const archived=source.match(/^git archive "\$SHA" (.+) \| tar -x -C "\$TMP"\r?$/m)?.[1].trim().split(/\s+/);
|
|
assert.deepEqual(archived,['website','tools','.forgejo']);
|
|
// web-repository-scope.test.mjs checks tools/README.md and the two web workflows.
|
|
assert.deepEqual(readFileSync(new URL('../../tools/README.md',import.meta.url),'utf8').length>0,true);
|
|
});
|

Staff