Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae6a591f9c |
No files matched your search
@@ -0,0 +1,82 @@
|
||||
name: Backend test probe
|
||||
|
||||
# Temporary: runs every backend test:all profile in the exact CI environment of
|
||||
# docker.yml/backend-test without publishing images. Removed after CI is fixed.
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- ci/backend-test-fix
|
||||
|
||||
jobs:
|
||||
backend-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node 22
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Start PostgreSQL 18
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
NAME="mm-pg-${{ gitea.run_id }}-${{ gitea.run_attempt }}"
|
||||
docker rm -f "$NAME" 2>/dev/null || true
|
||||
# Docker-backed Gitea runners execute this step in a separate container.
|
||||
# Join its network; a published host loopback port is not reachable here.
|
||||
NETWORKS=$(docker inspect --format '{{range $name, $network := .NetworkSettings.Networks}}{{println $name}}{{end}}' "$(cat /etc/hostname)" 2>/dev/null || true)
|
||||
if [ -n "$NETWORKS" ]; then
|
||||
test "$(printf '%s\n' "$NETWORKS" | wc -l)" -eq 1
|
||||
NETWORK_ARGS=(--network "$NETWORKS" --network-alias "$NAME")
|
||||
PG_HOST="$NAME"
|
||||
PG_PORT=5432
|
||||
else
|
||||
# Host-based runners can use a Docker-assigned ephemeral host port.
|
||||
NETWORK_ARGS=(-p 127.0.0.1::5432)
|
||||
PG_HOST=127.0.0.1
|
||||
fi
|
||||
docker run -d --name "$NAME" --rm \
|
||||
-e POSTGRES_USER=mmapp \
|
||||
-e POSTGRES_PASSWORD=mmapp \
|
||||
-e POSTGRES_DB=mmapp \
|
||||
"${NETWORK_ARGS[@]}" \
|
||||
postgres:18-alpine
|
||||
echo "PG_CONTAINER=$NAME" >> "${GITHUB_ENV}"
|
||||
if [ "$PG_HOST" = 127.0.0.1 ]; then
|
||||
PG_PORT=$(docker port "$NAME" 5432/tcp | awk -F: '{print $NF}')
|
||||
fi
|
||||
echo "DATABASE_URL=postgres://mmapp:mmapp@${PG_HOST}:${PG_PORT}/mmapp" >> "${GITHUB_ENV}"
|
||||
for i in $(seq 1 40); do
|
||||
if docker exec "$NAME" pg_isready -U mmapp -d mmapp; then
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "PostgreSQL не поднялся"
|
||||
docker logs "$NAME" || true
|
||||
exit 1
|
||||
|
||||
- name: Install and test backend (all profiles)
|
||||
shell: bash
|
||||
env:
|
||||
REQUIRE_TEST_POSTGRES: "1"
|
||||
run: |
|
||||
set -uo pipefail
|
||||
npm ci
|
||||
cd backend
|
||||
failed=""
|
||||
for profile in $(node -e "console.log(require('./package.json').scripts['test:all'].split(/\s*&&\s*/).map(c => c.replace('npm run ', '')).join(' '))"); do
|
||||
echo "PROFILE START $profile"
|
||||
if NODE_ENV=test npm run "$profile"; then echo "PROFILE PASS $profile"; else echo "PROFILE FAIL $profile"; failed="$failed $profile"; fi
|
||||
done
|
||||
echo "FAILED PROFILES:${failed:- none}"
|
||||
test -z "$failed"
|
||||
|
||||
- name: Stop PostgreSQL
|
||||
if: always()
|
||||
shell: bash
|
||||
run: docker rm -f "${PG_CONTAINER:-}" 2>/dev/null || true
|
||||
|
||||
@@ -3,13 +3,10 @@ import { spawnSync } from "node:child_process"
|
||||
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"))
|
||||
const npmCli = process.env.npm_execpath
|
||||
if (!npmCli) throw new Error("Запускайте тесты через npm --prefix backend test")
|
||||
const profiles = pkg.scripts["test:all"].split(/\s*&&\s*/).map(command => {
|
||||
const match = /^npm run (test:[\w-]+(?::[\w-]+)*)$/.exec(command)
|
||||
if (!match || !Object.hasOwn(pkg.scripts, match[1])) throw new Error(`Неизвестный профиль тестов backend: ${command}`)
|
||||
return match[1]
|
||||
})
|
||||
for (const profile of profiles) {
|
||||
const result = spawnSync(process.execPath, [npmCli, "run", profile], {
|
||||
for (const command of pkg.scripts["test:all"].split(/\s*&&\s*/)) {
|
||||
const match = /^npm run (test:[\w-]+)$/.exec(command)
|
||||
if (!match) throw new Error("Неизвестный формат профиля backend tests")
|
||||
const result = spawnSync(process.execPath, [npmCli, "run", match[1]], {
|
||||
cwd: new URL("../", import.meta.url),
|
||||
env: { ...process.env, NODE_ENV: "test" },
|
||||
stdio: "inherit",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import path from 'node:path'
|
||||
import {tmpdir} from 'node:os'
|
||||
import {mkdtemp,mkdir,writeFile,readFile,appendFile,rm,lstat,chmod,symlink} from 'node:fs/promises'
|
||||
import * as filesystem from 'node:fs/promises'
|
||||
import {fileURLToPath} from 'node:url'
|
||||
@@ -15,12 +14,12 @@ const target='postgresql://service:[email protected]:5432/managed?
|
||||
const record=(operationId:string,state:string)=>JSON.stringify({operationId,state,at:'2026-11-01T00:00:00.000Z'})+'\n'
|
||||
const source={systemIdentifier:'1234567890',databaseOid:'12345',databaseName:'managed',serverVersionNum:180004,inRecovery:false as const}
|
||||
const knownCurrent={transport:{mode:'tls' as const,endpointSha256:'f'.repeat(64)},source,schemaSha256:'a'.repeat(64),rawSchemaSha256:'b'.repeat(64),physicalSchemaSha256:'c'.repeat(64),manifestSha256:'d'.repeat(64),markersSha256:'e'.repeat(64)}
|
||||
async function own(work:(root:string,uncertain:string,applied:string)=>Promise<void>,base=temp){await mkdir(base,{recursive:true});const root=await mkdtemp(path.join(base,'owned-maintenance-resolution-'));try{
|
||||
async function own(work:(root:string,uncertain:string,applied:string)=>Promise<void>){await mkdir(temp,{recursive:true});const root=await mkdtemp(path.join(temp,'owned-maintenance-resolution-'));try{
|
||||
await mkdir(path.join(root,'restore-vault'));await writeFile(path.join(root,'access-generation'),Buffer.alloc(32,7));const uncertain=randomUUID(),applied=randomUUID()
|
||||
await writeFile(path.join(root,'database-maintenance.jsonl'),record(uncertain,'intent')+record(uncertain,'unconfirmed')+record(applied,'intent')+record(applied,'applied'))
|
||||
for(const [id,state]of [[uncertain,'unknown'],[applied,'applied']]){const archiveRef=randomUUID(),at='2026-11-01T00:00:00.000Z';await writeFile(path.join(root,'restore-vault',archiveRef+'.used'),JSON.stringify({operationId:id,at}));await writeFile(path.join(root,'restore-vault',id+'.receipt.json'),JSON.stringify({operationId:id,archiveRef,state,startedAt:at,automaticRetry:false,...(state==='applied'?{finishedAt:at,accessRevoked:true,warnings:[]}:{errorCode:'RESTORE_UNCONFIRMED',finishedAt:at})}))}
|
||||
await work(root,uncertain,applied)
|
||||
}finally{assert(path.dirname(root)===base&&path.basename(root).startsWith('owned-maintenance-resolution-'));await rm(root,{recursive:true,force:true})}}
|
||||
}finally{assert(path.dirname(root)===temp&&path.basename(root).startsWith('owned-maintenance-resolution-'));await rm(root,{recursive:true,force:true})}}
|
||||
export async function modeledStartup(){
|
||||
// This is deliberately a MODELED POSIX ownership adapter over actual owned
|
||||
// files on Windows, not evidence that Windows/Linux protection was accepted.
|
||||
@@ -140,14 +139,12 @@ test('new unresolved vault marker blocks even without a new core journal record'
|
||||
|
||||
test('native POSIX immutable fsynced acceptance is consumed by actual startup; mode and symlink drift refuse',async context=>{
|
||||
if(process.platform==='win32'){context.skip('Native POSIX filesystem acceptance must run directly on Linux; Windows model is not proof');return}
|
||||
// protectedDirectory requires every parent to be non-writable by others; a CI checkout may not be, the system temp root is.
|
||||
const base=await mkdtemp(path.join(tmpdir(),'mm-posix-maintenance-'))
|
||||
try{await own(async root=>{
|
||||
await own(async root=>{
|
||||
const {writeFile:writeProtected}=await import('../../scripts/writer-profile/operator-files.mjs'),value=await acceptance(root),directory=path.join(root,'maintenance-acceptances'),filename=path.join(directory,value.resolutionId+'.json')
|
||||
await mkdir(directory,{mode:0o700});await writeProtected(filename,Buffer.from(JSON.stringify(value)),{flag:'wx',mode:0o600})
|
||||
assert.equal((await inspectDatabaseMaintenanceStartup(root,target)).classification,'accepted-current-state')
|
||||
await chmod(filename,0o644);assert.equal((await inspectDatabaseMaintenanceStartup(root,target)).classification,'inspection-required');await chmod(filename,0o600)
|
||||
const alias=path.join(directory,randomUUID()+'.json');await symlink(filename,alias);assert.equal((await inspectDatabaseMaintenanceStartup(root,target)).classification,'inspection-required');await rm(alias)
|
||||
const later=randomUUID();await appendFile(path.join(root,'database-maintenance.jsonl'),record(later,'intent')+record(later,'applied'));assert.equal((await inspectDatabaseMaintenanceStartup(root,target)).classification,'accepted-current-state')
|
||||
},base)}finally{await rm(base,{recursive:true,force:true})}
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user