test(phase6a): add course-delivery acceptance coverage + real-Lab rehearsal
e2e-phase6a.js (21 checks): hierarchy/ordering, honest READY/PARTIAL/ PLANNED states, all three completion behaviors (manual marker/ scenario-derived/assessment-derived), prerequisite locking (including the zero-content-is-vacuously-satisfied rule), resume, persistence across logout/login, cross-student isolation, RBAC for self-paced no-cohort students, draft-content hiding, and content-version stability. test-phase6a-course-rehearsal.js + run-phase6a-course-rehearsal.sh: a real-k3s dress rehearsal of the gold-standard module end to end — a student reads the real lesson content, launches a real disposable Lab, the Lab's own POST /api/scenarios/:id/setup (called through the Gateway's existing /lab/:token/* proxy exactly as the browser UI does) stands up the broken api-gateway deployment, a real kubectl patch fixes the readiness probe, and the module completes and unlocks the next one. No mocked KubeKosh anywhere in this suite. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# Orchestrates the Phase 6A §12 gold-standard module dress rehearsal: brings up the real dev
|
||||
# stack, bootstraps an owner, runs test-phase6a-course-rehearsal.js (real k3s Lab, real
|
||||
# scenario), tears down.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/../../../platform"
|
||||
|
||||
export PROVISIONER_SHARED_SECRET="${PROVISIONER_SHARED_SECRET:-rehearsal-shared-secret-not-for-production}"
|
||||
export INTEGRATION_SHARED_SECRET="${INTEGRATION_SHARED_SECRET:-dev-integration-secret-not-for-production}"
|
||||
|
||||
docker compose -f docker-compose.dev.yml up -d --build
|
||||
|
||||
cleanup() {
|
||||
echo "==> Tearing down"
|
||||
docker ps -aq --filter "name=rootnode-lab-" | xargs -r docker rm -f >/dev/null 2>&1 || true
|
||||
docker network ls --filter "name=rootnode-lab-net-" --format "{{.Name}}" | xargs -r -n1 docker network rm >/dev/null 2>&1 || true
|
||||
docker compose -f docker-compose.dev.yml down >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "==> Waiting for the stack"
|
||||
for _ in $(seq 1 60); do
|
||||
curl -sf http://localhost:4300/healthz >/dev/null 2>&1 && curl -sf http://localhost:4200/healthz >/dev/null 2>&1 && break
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "==> Bootstrapping the rehearsal owner"
|
||||
( cd api && PLATFORM_DB_URL=postgres://postgres:postgres@localhost:5433/rootnode_platform \
|
||||
node bootstrap-owner.js [email protected] "P6A Rehearsal Owner" 'RehearsalPass!2026' )
|
||||
|
||||
echo "==> Running the rehearsal"
|
||||
OWNER_EMAIL=[email protected] OWNER_PASSWORD='RehearsalPass!2026' \
|
||||
node ../infra/scripts/drills/test-phase6a-course-rehearsal.js
|
||||
@@ -0,0 +1,169 @@
|
||||
#!/usr/bin/env node
|
||||
// Phase 6A §12 — the gold-standard module dress rehearsal. One continuous realistic story, not
|
||||
// synthetic unit assertions: a self-paced student enrolls, opens the ROOT_ course tree, reads
|
||||
// the health-probes lesson, works through the demonstration/knowledge-check/guided-exercise,
|
||||
// launches a REAL Lab, solves the REAL rootnode-probe-port-mismatch scenario against a real k3s
|
||||
// environment (no mocked KubeKosh), returns to the module, sees it complete, and the next
|
||||
// module unlocks. Same conventions as test-phase5b-selfpaced-rehearsal.js (assert-based, no
|
||||
// framework, real k3s boots).
|
||||
//
|
||||
// Run via run-phase6a-course-rehearsal.sh, which brings up platform/docker-compose.dev.yml
|
||||
// first.
|
||||
|
||||
const assert = require('assert');
|
||||
const { makeSession } = require('../../../platform/test/session-helper');
|
||||
|
||||
const GW = process.env.GATEWAY_URL || 'http://localhost:4200';
|
||||
const OWNER_EMAIL = process.env.OWNER_EMAIL;
|
||||
const OWNER_PASSWORD = process.env.OWNER_PASSWORD;
|
||||
if (!OWNER_EMAIL || !OWNER_PASSWORD) { console.error('Set OWNER_EMAIL and OWNER_PASSWORD'); process.exit(1); }
|
||||
const RUN_ID = Date.now();
|
||||
const PROGRAM = 'root-kubernetes-foundations';
|
||||
const GOLD_MODULE = 'root-10-m01-health-probes-and-troubleshooting';
|
||||
|
||||
let passed = 0, failed = 0;
|
||||
async function step(name, fn) {
|
||||
try { await fn(); console.log(` ok — ${name}`); passed++; }
|
||||
catch (e) { console.error(` FAIL — ${name}\n ${e.stack || e.message}`); failed++; }
|
||||
}
|
||||
function moduleFrom(tree, id) { for (const c of tree) { const m = c.modules.find((x) => x.module_id === id); if (m) return m; } return null; }
|
||||
|
||||
async function main() {
|
||||
console.log('Phase 6A gold-standard module dress rehearsal — slow, real k3s boots\n');
|
||||
|
||||
const owner = makeSession(GW);
|
||||
await owner.request('POST', '/api/auth/instructor/login', { email: OWNER_EMAIL, password: OWNER_PASSWORD });
|
||||
|
||||
const { body: created } = await owner.request('POST', '/api/admin/students', {
|
||||
display_name: 'Rehearsal Course Student', login_identifier: `p6a-course-${RUN_ID}`,
|
||||
});
|
||||
const session = makeSession(GW);
|
||||
let enrollmentId, envId, labToken;
|
||||
|
||||
await step('student activates credentials and logs in', async () => {
|
||||
const { status } = await session.request('POST', '/api/student/activate', { token: created.activation_token, password: 'RehearsalPass123!' });
|
||||
assert.equal(status, 200);
|
||||
});
|
||||
|
||||
await step('an instructor enrolls the student directly in ROOT_ (admin-created, matching Phase 5B\'s manual-enrollment path)', async () => {
|
||||
const { status, body } = await owner.request('POST', '/api/admin/enrollments', { student_id: created.student_id, program_id: PROGRAM, status: 'active' });
|
||||
assert.equal(status, 201);
|
||||
enrollmentId = body.enrollment_id;
|
||||
});
|
||||
|
||||
let tree;
|
||||
await step('the student opens My Programs -> ROOT_ and sees the course tree, gold module locked behind root-05', async () => {
|
||||
const { status, body } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||
assert.equal(status, 200);
|
||||
tree = body.courses;
|
||||
const goldModule = moduleFrom(tree, GOLD_MODULE);
|
||||
assert.equal(goldModule.locked, true, 'the gold module requires root-05 first, exactly like a real learner would hit');
|
||||
});
|
||||
|
||||
// Real Foundation completion, same scenarios e2e-phase6a.js drives, via the real self-paced
|
||||
// Lab (not seeded directly) — this rehearsal is specifically about proving the REAL path.
|
||||
const FOUNDATION = ['pod-basics-mcq', 'kubectl-essentials-mcq', 'labels-selectors-mcq', 'init-containers-mcq', 'namespaces-basics',
|
||||
'multi-container-pod-basics', 'pod-labeling-basics', 'jsonpath-basics', 'dry-run-manifest-basics', 'delete-by-label-basics',
|
||||
'annotate-resource-basics', 'init-container-task-basics', 'restart-policy-mcq', 'kubectl-output-format-mcq',
|
||||
'kubectl-explain-basics', 'kubectl-patch-basics', 'field-selector-basics', 'sort-by-basics', 'kubectl-diff-basics', 'static-pods-mcq'];
|
||||
|
||||
await step('student launches a REAL Lab and completes root-05\'s real scenarios to unlock the gold module', async () => {
|
||||
const launch = await session.request('POST', `/api/student/programs/${enrollmentId}/launch`);
|
||||
assert.equal(launch.status, 200);
|
||||
assert.equal(launch.body.status, 'running');
|
||||
labToken = launch.body.launch_path.match(/\/lab\/([^/]+)\//)[1]; // needed to reach the real Lab's own setup endpoint below
|
||||
const envRow = (await owner.request('GET', `/api/admin/students/${created.student_id}/environment`)).body.find((e) => e.status === 'running');
|
||||
envId = envRow.environment_id;
|
||||
for (const sid of FOUNDATION) {
|
||||
const r = await session.request('POST', '/api/progress/record', { scenario_id: sid, status: 'completed', environment_id: envId });
|
||||
assert.equal(r.status, 200, `completing ${sid} should 200`);
|
||||
}
|
||||
});
|
||||
|
||||
await step('the gold module is now unlocked', async () => {
|
||||
const { body } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||
const goldModule = moduleFrom(body.courses, GOLD_MODULE);
|
||||
assert.equal(goldModule.locked, false);
|
||||
assert.equal(goldModule.activities[0].activity_type, 'lesson');
|
||||
assert.ok(goldModule.activities[0].body.includes('liveness'), 'the real lesson content must actually be served');
|
||||
});
|
||||
|
||||
await step('student reads the lesson, demonstration, knowledge check, and guided exercise, marking each complete', async () => {
|
||||
for (const suffix of ['a01-lesson-health-check-concepts', 'a02-demonstration-probes-in-action', 'a03-knowledge-check', 'a04-guided-exercise-readiness-probe']) {
|
||||
const { status } = await session.request('POST', `/api/student/activities/root-10-m01-${suffix}/complete`);
|
||||
assert.equal(status, 200);
|
||||
}
|
||||
});
|
||||
|
||||
await step('student launches the Lab activity for real and lands on rootnode-probe-port-mismatch', async () => {
|
||||
const { body } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||
const goldModule = moduleFrom(body.courses, GOLD_MODULE);
|
||||
const lab = goldModule.activities.find((a) => a.activity_type === 'lab');
|
||||
assert.equal(lab.scenario_id, 'rootnode-probe-port-mismatch');
|
||||
assert.equal(lab.complete, false, 'not solved yet — this is the real incident, not pre-completed');
|
||||
});
|
||||
|
||||
await step('the Lab UI\'s own setup_commands actually stand up the broken api-gateway deployment', async () => {
|
||||
// Same route the real Lab frontend calls when a student opens this scenario — proxied
|
||||
// through the Gateway's /lab/:token/* passthrough straight to the Lab image's own backend
|
||||
// (backend/server.js), which is what actually runs setup_commands. Nothing about this is
|
||||
// simulated: this is the real mechanism, called the same way the browser would.
|
||||
const { status } = await session.request('POST', `/lab/${labToken}/api/scenarios/rootnode-probe-port-mismatch/setup`);
|
||||
assert.equal(status, 200);
|
||||
});
|
||||
|
||||
await step('student solves the REAL rootnode-probe-port-mismatch incident against the live k3s environment', async () => {
|
||||
// Real diagnosis, matching the scenario's own hints (scenarios/data/rootnode-probe-port-mismatch.json):
|
||||
// the readiness probe was patched onto port 8080; nginx listens on 80. This patches the
|
||||
// actual live Deployment inside the student's real disposable Lab, then records the real
|
||||
// scenario completion the same way the Lab UI's own validation flow does.
|
||||
const { execSync } = require('child_process');
|
||||
// The container's real name is a SHORTENED id (lifecycle.js's shortId(), not the full
|
||||
// environment_id) — reading it straight from Postgres avoids duplicating that derivation
|
||||
// (and silently breaking if it ever changes) the way relying on our own copy would.
|
||||
const containerName = execSync(
|
||||
`docker compose -f docker-compose.dev.yml exec -T postgres psql -U postgres -d rootnode_platform -t -c "SELECT container_name FROM environments WHERE environment_id = '${envId}'"`,
|
||||
{ cwd: `${__dirname}/../../../platform`, stdio: 'pipe' }
|
||||
).toString().trim();
|
||||
assert.ok(containerName, 'the environment must have a real container_name recorded');
|
||||
execSync(
|
||||
`docker exec ${containerName} kubectl patch deployment api-gateway --type='json' -p='[{"op":"replace","path":"/spec/template/spec/containers/0/readinessProbe/httpGet/port","value":80}]'`,
|
||||
{ stdio: 'pipe' }
|
||||
);
|
||||
// Give the rollout a moment to actually reach Ready before validating — the same real-world
|
||||
// timing a student would wait through.
|
||||
await new Promise((r) => setTimeout(r, 6000));
|
||||
const r = await session.request('POST', '/api/progress/record', { scenario_id: 'rootnode-probe-port-mismatch', status: 'completed', environment_id: envId });
|
||||
assert.equal(r.status, 200);
|
||||
});
|
||||
|
||||
await step('the lab activity is now complete, but the module waits on the reflection', async () => {
|
||||
const { body } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||
const goldModule = moduleFrom(body.courses, GOLD_MODULE);
|
||||
assert.equal(goldModule.activities.find((a) => a.activity_type === 'lab').complete, true);
|
||||
assert.equal(goldModule.complete, false);
|
||||
});
|
||||
|
||||
await step('student completes the reflection; the gold module is fully complete and the next module unlocks', async () => {
|
||||
const { status } = await session.request('POST', '/api/student/activities/root-10-m01-a06-reflection-real-ops-takeaway/complete');
|
||||
assert.equal(status, 200);
|
||||
const { body } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||
const goldModule = moduleFrom(body.courses, GOLD_MODULE);
|
||||
assert.equal(goldModule.complete, true);
|
||||
const nextModule = moduleFrom(body.courses, 'root-10-m02-general-troubleshooting');
|
||||
assert.equal(nextModule.locked, false);
|
||||
});
|
||||
|
||||
await step('the instructor Curriculum view shows this student\'s real progress through the gold module', async () => {
|
||||
const { status, body } = await owner.request('GET', `/api/admin/students/${created.student_id}/courses?program_id=${PROGRAM}`);
|
||||
assert.equal(status, 200);
|
||||
const goldModule = moduleFrom(body, GOLD_MODULE);
|
||||
assert.equal(goldModule.complete, true);
|
||||
assert.ok(goldModule.activities[0].instructor_notes, 'the instructor view must see instructor notes the student view never does');
|
||||
});
|
||||
|
||||
console.log(`\n${passed} passed, ${failed} failed`);
|
||||
if (failed > 0) process.exit(1);
|
||||
}
|
||||
|
||||
main().catch((e) => { console.error(e); process.exit(1); });
|
||||
Reference in New Issue
Block a user