Keep dev-key tests outside website-only deployment archive

This commit is contained in:
unimatrixgit 2026-11-18 21:43:44 +01:00
commit f9d57eff19
3 changed files with 91 additions and 90 deletions

View file

@ -1,86 +1,87 @@
name: DuneRealms Web CI
on:
push:
branches:
- main
paths:
- 'website/**'
- '.forgejo/workflows/web-deploy.yml'
workflow_dispatch:
jobs:
web:
runs-on: dune-ci
steps:
- name: Checkout
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git init .
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/MC.git "$GITHUB_SHA"
git checkout --detach FETCH_HEAD
- name: Install Node 22
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Prepare publication comparison
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BEFORE=$(node -e 'const fs=require("fs");const p=process.env.GITHUB_EVENT_PATH;const e=p&&fs.existsSync(p)?JSON.parse(fs.readFileSync(p)):{};process.stdout.write(e.before||"");')
if [[ ! "$BEFORE" =~ ^[0-9a-f]{40}$ || "$BEFORE" =~ ^0+$ ]]; then
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --deepen=1 https://www.dunerealms.com/git/unimatrix/MC.git "$GITHUB_SHA"
BEFORE=$(git rev-parse HEAD^)
else
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/MC.git "$BEFORE"
fi
node website/scripts/publication-changes.mjs "$BEFORE" "$GITHUB_SHA"
- name: Verify deployment policy
run: |
node --test .forgejo/tests/web-deploy.test.mjs
python3 -m unittest discover -s website/ops -p 'test_*.py'
- name: Build and test website
working-directory: website
run: |
corepack enable
corepack pnpm install --frozen-lockfile
corepack pnpm build
corepack pnpm test
- name: Upload website build
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3
with:
name: DuneRealms-Website
path: website/dist/
if-no-files-found: error
retention-days: 1
- name: Trigger deployment after successful CI
if: github.ref == 'refs/heads/main'
shell: bash
env:
DEPLOY_KEY: ${{ secrets.DUNEREALMS_DEPLOY_KEY }}
run: |
install -m 700 -d ~/.ssh
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
trap 'rm -f ~/.ssh/deploy_key' EXIT
printf '%s\n' '91.107.196.242 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC8x/XocsIz41fWHGty0DbZhSvafSQFt9jaHHgzdr55W root@ubuntu-4gb-fsn1-1' >> ~/.ssh/known_hosts
ssh -p 22 -i ~/.ssh/deploy_key -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes dunedeploy@91.107.196.242 "$GITHUB_SHA"
rm -f ~/.ssh/deploy_key
- name: Prune previous CI artifacts after confirmed publication
if: github.ref == 'refs/heads/main'
continue-on-error: true
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node website/scripts/prune-ci-artifacts.mjs
name: DuneRealms Web CI
on:
push:
branches:
- main
paths:
- 'website/**'
- '.forgejo/workflows/web-deploy.yml'
workflow_dispatch:
jobs:
web:
runs-on: dune-ci
steps:
- name: Checkout
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git init .
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/MC.git "$GITHUB_SHA"
git checkout --detach FETCH_HEAD
- name: Install Node 22
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Prepare publication comparison
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BEFORE=$(node -e 'const fs=require("fs");const p=process.env.GITHUB_EVENT_PATH;const e=p&&fs.existsSync(p)?JSON.parse(fs.readFileSync(p)):{};process.stdout.write(e.before||"");')
if [[ ! "$BEFORE" =~ ^[0-9a-f]{40}$ || "$BEFORE" =~ ^0+$ ]]; then
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --deepen=1 https://www.dunerealms.com/git/unimatrix/MC.git "$GITHUB_SHA"
BEFORE=$(git rev-parse HEAD^)
else
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/MC.git "$BEFORE"
fi
node website/scripts/publication-changes.mjs "$BEFORE" "$GITHUB_SHA"
- name: Verify deployment policy
run: |
node --test .forgejo/tests/web-deploy.test.mjs
python3 -m unittest discover -s website/ops -p 'test_*.py'
- name: Build and test website
working-directory: website
run: |
corepack enable
corepack pnpm install --frozen-lockfile
corepack pnpm build
corepack pnpm test
node --test --test-concurrency=1 ../tools/tests/*.test.mjs
- name: Upload website build
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3
with:
name: DuneRealms-Website
path: website/dist/
if-no-files-found: error
retention-days: 1
- name: Trigger deployment after successful CI
if: github.ref == 'refs/heads/main'
shell: bash
env:
DEPLOY_KEY: ${{ secrets.DUNEREALMS_DEPLOY_KEY }}
run: |
install -m 700 -d ~/.ssh
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
trap 'rm -f ~/.ssh/deploy_key' EXIT
printf '%s\n' '91.107.196.242 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC8x/XocsIz41fWHGty0DbZhSvafSQFt9jaHHgzdr55W root@ubuntu-4gb-fsn1-1' >> ~/.ssh/known_hosts
ssh -p 22 -i ~/.ssh/deploy_key -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes dunedeploy@91.107.196.242 "$GITHUB_SHA"
rm -f ~/.ssh/deploy_key
- name: Prune previous CI artifacts after confirmed publication
if: github.ref == 'refs/heads/main'
continue-on-error: true
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node website/scripts/prune-ci-artifacts.mjs

View file

@ -0,0 +1,34 @@
import test from 'node:test';import assert from 'node:assert/strict';import {randomUUID} from 'node:crypto';
import {BankFixture} from '../../website/tests/postbank-fixture.mjs';
import {createDevKeyAuthority} from '../jarvis-dev-key.mjs';
import {clanResetManifest,executeClanReset} from '../jarvis-dev-clan-reset.mjs';
function fixture(){const db=new BankFixture();db.sqlite.exec(`
CREATE TABLE site_accounts(id TEXT PRIMARY KEY,username TEXT);
CREATE TABLE site_clans(id TEXT PRIMARY KEY,name TEXT,owner_id TEXT,active INT,version INT,updated_at INT);
CREATE TABLE site_clan_institutions(clan_id TEXT PRIMARY KEY,institution_key TEXT);
CREATE TABLE site_clan_members(user_id TEXT PRIMARY KEY,clan_id TEXT,clan_role TEXT);
CREATE TABLE site_clan_requests(clan_id TEXT,user_id TEXT,status TEXT,updated_at INT);
CREATE TABLE account_audit(id TEXT PRIMARY KEY,actor_id TEXT,action TEXT,details TEXT,created_at INT);
INSERT INTO site_accounts VALUES('owner','unimatrix999');
INSERT INTO site_clans VALUES('mine','My house','owner',1,1,0),('official','Office','other',1,1,0),('test','Test','other',1,1,0);
INSERT INTO site_clan_institutions VALUES('official','house');
INSERT INTO site_clan_members VALUES('owner','mine','owner'),('blue','mine','member'),('office-member','official','member'),('test-member','test','member');
INSERT INTO site_clan_requests VALUES('test','applicant','pending',0);`);return db;}
test('signed dev key executes actual clan SQL, keeps protected rosters, and cannot repeat the batch',async()=>{
const db=fixture(),actor={id:'developer'},authority=createDevKeyAuthority({secret:'ab'.repeat(32),environment:'test',authorize:async u=>u.id===actor.id});
try{const result=await db.transaction(async tx=>{
const manifest=await clanResetManifest(tx,'unimatrix999'),issued=await authority.issue(actor,manifest),record=await authority.verify(actor,issued.key,manifest);
const result=await executeClanReset(tx,{record,expectedManifest:manifest,batchId:'test-reset'});
assert.equal((await executeClanReset(tx,{record,expectedManifest:manifest,batchId:'test-reset'})).replayed,true);return result;
});assert.equal(result.archived,1);assert.equal((await db.first("SELECT active FROM site_clans WHERE id='test'")).active,0);
assert.deepEqual((await db.query('SELECT user_id FROM site_clan_members ORDER BY user_id')).map(r=>r.user_id),['blue','office-member','owner']);
assert.equal((await db.first("SELECT status FROM site_clan_requests WHERE clan_id='test'")).status,'closed');
assert.equal((await db.query("SELECT id FROM account_audit WHERE action='dev-clan-reset-complete'")).length,1);
}finally{db.close();}
});
test('failure rolls back all reset steps and audit, allowing a clean retry',async()=>{
const db=fixture();try{await assert.rejects(db.transaction(async tx=>{
const manifest=await clanResetManifest(tx,'unimatrix999');await executeClanReset(tx,{record:{id:randomUUID(),manifest,manifestHash:'test'},expectedManifest:manifest,batchId:'rollback'});throw Error('Injected');
}),/Injected/);assert.equal((await db.first("SELECT active FROM site_clans WHERE id='test'")).active,1);assert.equal((await db.query('SELECT id FROM account_audit')).length,0);
}finally{db.close();}
});

View file

@ -0,0 +1,19 @@
import test from 'node:test';import assert from 'node:assert/strict';
import {createDevKeyAuthority} from '../jarvis-dev-key.mjs';
const dev={id:'developer'},manifest={action:'clan-reset',state:'planned',deleteClanIds:['test'],retainClanIds:['official','mine']};
const setup=(extra={})=>createDevKeyAuthority({secret:'ab'.repeat(32),environment:'test',authorize:async actor=>actor.id===dev.id,...extra});
test('dev key binds exact manifest, actor and environment, and audit contains no secret',async()=>{
const service=setup(),issued=await service.issue(dev,manifest);
assert.equal((await service.verify(dev,issued.key,manifest)).id,issued.record.id);
assert(!JSON.stringify(issued.audit).includes(issued.key));assert(!Object.hasOwn(issued.audit,'key'));
await assert.rejects(service.verify(dev,issued.key,{...manifest,deleteClanIds:['mine']}),/manifest/);
await assert.rejects(setup({environment:'production'}).verify(dev,issued.key,manifest),/unavailable/);
await assert.rejects(service.verify({id:'staff'},issued.key,manifest),/Developer access/);
});
test('expiry, tampering and unavailable developer privileges reject before execution',async()=>{
let now=10000;const service=setup({clock:()=>now}),issued=await service.issue(dev,manifest,{ttlMs:100});
const parts=issued.key.split('.');parts[2]=(parts[2][0]==='0'?'1':'0')+parts[2].slice(1);
await assert.rejects(service.verify(dev,parts.join('.'),manifest),/Invalid/);
now=10100;await assert.rejects(service.verify(dev,issued.key,manifest),/unavailable/);
await assert.rejects(setup({authorize:async()=>false}).issue(dev,manifest),/Developer access/);
});