Skip to content

Commit fd141bb

Browse files
committed
refactor(V2): move non-home sync wait into data-short orchestrator
Remove the curl-based ownership test from v2 remote sync tests (keep that job focused on sync verification). Move the non-home project polling wait from the CI shell into data-short.js right before Phase 4 (PUT tests) so POST tests run without delay and governance has maximum time to sync before the ownership guard tests need the data.
1 parent 8a7350f commit fd141bb

2 files changed

Lines changed: 31 additions & 84 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -482,28 +482,6 @@ jobs:
482482
echo "########################################################"
483483
npm run test:v2:live:wallet-health
484484
echo "########################################################"
485-
echo "Waiting for non-home project from governance sync"
486-
echo "########################################################"
487-
MAX_WAIT=600
488-
ELAPSED=0
489-
while [ "$ELAPSED" -lt "$MAX_WAIT" ]; do
490-
PROJECTS=$(curl -s "http://${TEST_API_HOST:-127.0.0.1}:31310/v2/project?page=1&limit=100" 2>/dev/null || echo "[]")
491-
NON_HOME=$(echo "$PROJECTS" | jq '[
492-
(if type == "object" then .data else . end)[]
493-
| select(.orgUid != null and .orgUid != "'"$(curl -s "http://${TEST_API_HOST:-127.0.0.1}:31310/v2/organizations" 2>/dev/null | jq -r 'to_entries[] | select(.value.isHome == true) | .key')"'")
494-
] | length' 2>/dev/null || echo "0")
495-
if [ "$NON_HOME" -gt 0 ] 2>/dev/null; then
496-
echo "Found $NON_HOME non-home project(s) after ${ELAPSED}s"
497-
break
498-
fi
499-
echo "No non-home projects yet (${ELAPSED}s / ${MAX_WAIT}s)..."
500-
sleep 30
501-
ELAPSED=$((ELAPSED + 30))
502-
done
503-
if [ "$ELAPSED" -ge "$MAX_WAIT" ]; then
504-
echo "WARNING: No non-home projects appeared after ${MAX_WAIT}s. Ownership guard tests will fail."
505-
fi
506-
echo "########################################################"
507485
echo "Running data tests"
508486
echo "########################################################"
509487
npm run test:v2:live:data:short
@@ -4383,68 +4361,6 @@ jobs:
43834361
fi
43844362
echo "All AEF data matches expected values"
43854363
4386-
- name: Verify ownership guards block non-home mutations
4387-
shell: bash
4388-
run: |
4389-
echo "########################################################"
4390-
echo "Verifying ownership guards reject non-home org mutations"
4391-
echo "########################################################"
4392-
BASE="http://127.0.0.1:31310/v2"
4393-
ERRORS=0
4394-
4395-
PROJECT=$(curl -s "$BASE/project?page=1&limit=1" | jq '(if type == "object" then .data else . end)[0]')
4396-
PROJECT_ID=$(echo "$PROJECT" | jq -r '.cadTrustProjectId')
4397-
echo "Using synced project: $PROJECT_ID"
4398-
4399-
echo ""
4400-
echo "--- PUT update on non-home project (expect 400) ---"
4401-
PUT_RESP=$(curl -s -w "\n%{http_code}" -X PUT "$BASE/project/$PROJECT_ID" \
4402-
-H "Content-Type: application/json" \
4403-
-d "{\"projectName\": \"Should Not Update $(date +%s)\"}")
4404-
PUT_HTTP=$(echo "$PUT_RESP" | tail -1)
4405-
PUT_BODY=$(echo "$PUT_RESP" | head -n -1)
4406-
if [ "$PUT_HTTP" = "400" ]; then
4407-
echo " PASS: PUT returned 400"
4408-
if echo "$PUT_BODY" | jq -r '.error' 2>/dev/null | grep -q "Restricted data"; then
4409-
echo " PASS: Error contains 'Restricted data'"
4410-
else
4411-
echo " FAIL: Expected 'Restricted data' in error body"
4412-
echo " Body: $PUT_BODY"
4413-
ERRORS=$((ERRORS + 1))
4414-
fi
4415-
else
4416-
echo " FAIL: Expected HTTP 400, got $PUT_HTTP"
4417-
echo " Body: $PUT_BODY"
4418-
ERRORS=$((ERRORS + 1))
4419-
fi
4420-
4421-
echo ""
4422-
echo "--- DELETE on non-home project (expect 400) ---"
4423-
DEL_RESP=$(curl -s -w "\n%{http_code}" -X DELETE "$BASE/project/$PROJECT_ID")
4424-
DEL_HTTP=$(echo "$DEL_RESP" | tail -1)
4425-
DEL_BODY=$(echo "$DEL_RESP" | head -n -1)
4426-
if [ "$DEL_HTTP" = "400" ]; then
4427-
echo " PASS: DELETE returned 400"
4428-
if echo "$DEL_BODY" | jq -r '.error' 2>/dev/null | grep -q "Restricted data"; then
4429-
echo " PASS: Error contains 'Restricted data'"
4430-
else
4431-
echo " FAIL: Expected 'Restricted data' in error body"
4432-
echo " Body: $DEL_BODY"
4433-
ERRORS=$((ERRORS + 1))
4434-
fi
4435-
else
4436-
echo " FAIL: Expected HTTP 400, got $DEL_HTTP"
4437-
echo " Body: $DEL_BODY"
4438-
ERRORS=$((ERRORS + 1))
4439-
fi
4440-
4441-
echo ""
4442-
if [ "$ERRORS" -gt 0 ]; then
4443-
echo "FAILED: $ERRORS ownership guard checks failed"
4444-
exit 1
4445-
fi
4446-
echo "All ownership guard checks passed"
4447-
44484364
- name: Show CADT logs after tests
44494365
if: always()
44504366
shell: bash

tests/v2/live-api/data-short.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
verifyMirrorRecordsBatch,
1818
closeMirrorDbPool,
1919
} from './helpers/mysql-mirror-helpers.js';
20+
import { getSharedHomeOrgId } from './helpers/shared-setup.js';
2021

2122
const __filename = fileURLToPath(import.meta.url);
2223
const __dirname = dirname(__filename);
@@ -421,6 +422,36 @@ async function main() {
421422
const xlsxTestFiles = ['xlsx-import-export.live.spec.js'];
422423
await runMochaTests('Step 1[1-6]a?:', 'XLSX Import/Export', xlsxTestFiles);
423424

425+
// Wait for governance to sync at least one non-home project before PUT/DELETE
426+
// tests that verify ownership guards reject mutations on foreign records.
427+
const homeOrgId = getSharedHomeOrgId();
428+
if (homeOrgId) {
429+
console.log('--- Waiting for non-home project from governance sync ---');
430+
const maxWaitMs = 600_000;
431+
const pollIntervalMs = 30_000;
432+
const startTime = Date.now();
433+
let found = false;
434+
while (Date.now() - startTime < maxWaitMs) {
435+
const elapsed = Math.round((Date.now() - startTime) / 1000);
436+
try {
437+
const res = await request.get('/v2/project').query({ page: 1, limit: 100 });
438+
const data = Array.isArray(res.body) ? res.body : (res.body?.data || []);
439+
const nonHome = data.find(r => r.orgUid && r.orgUid !== homeOrgId);
440+
if (nonHome) {
441+
console.log(` ✓ Found non-home project after ${elapsed}s (orgUid=${nonHome.orgUid.slice(0, 12)}...)`);
442+
found = true;
443+
break;
444+
}
445+
} catch { /* ignore transient errors */ }
446+
console.log(` No non-home projects yet (${elapsed}s / ${maxWaitMs / 1000}s)...`);
447+
await new Promise(r => setTimeout(r, pollIntervalMs));
448+
}
449+
if (!found) {
450+
console.log(' ⚠ WARNING: No non-home projects appeared. Ownership guard tests will fail.');
451+
}
452+
console.log('');
453+
}
454+
424455
// Phase 4: PUT tests
425456
await runMochaTests('Step 7: PUT Request Tests', 'PUT Operations');
426457
await commitAndWait('PUT');

0 commit comments

Comments
 (0)