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); });
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// Phase 6A — course/module/activity content model acceptance test. Covers course/module/
|
||||||
|
// activity hierarchy and ordering, prerequisite-based locking, all three completion behaviors
|
||||||
|
// (manual_marker/auto_scenario/auto_assessment) derived from the EXISTING progress/achievements
|
||||||
|
// tables (never a second source of truth), resume-next-activity, cross-student isolation, RBAC
|
||||||
|
// (self-paced no-cohort students), draft-content hiding, and persistence across logout/login.
|
||||||
|
// Same conventions as e2e-phase5b.js/e2e-phase5c.js: assert-based, no framework, live
|
||||||
|
// docker-compose.dev.yml stack. No real Lab container is launched here — that's
|
||||||
|
// infra/scripts/drills/test-phase6a-course-rehearsal.js's job (uses the real Lab environment);
|
||||||
|
// this suite proves the API/data model, using /api/progress/record directly the same way
|
||||||
|
// e2e-phase3b.js/e2e-phase5b.js already do for scenario completion.
|
||||||
|
//
|
||||||
|
// Usage: cd platform && docker compose -f docker-compose.dev.yml up -d
|
||||||
|
// (cd api && PLATFORM_DB_URL=... node bootstrap-owner.js OWNER_EMAIL "Owner" OWNER_PASSWORD)
|
||||||
|
// OWNER_EMAIL=... OWNER_PASSWORD=... node test/e2e-phase6a.js
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const { makeSession } = require('./session-helper');
|
||||||
|
|
||||||
|
const GW = process.env.GATEWAY_URL || 'http://localhost:4200';
|
||||||
|
const API = process.env.PLATFORM_API_URL || 'http://localhost:4300';
|
||||||
|
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 (bootstrap one first with platform/api/bootstrap-owner.js)');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
const RUN_ID = Date.now();
|
||||||
|
const PROGRAM = 'root-kubernetes-foundations';
|
||||||
|
|
||||||
|
// Same real curriculum snapshot e2e-phase3b.js/e2e-phase5b.js already drive full completion
|
||||||
|
// against — see those files' headers for why this is a real, not synthetic, content list.
|
||||||
|
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'];
|
||||||
|
const WORKLOADS = ['deploy-nginx', 'scale-deployment', 'rolling-update-task', 'liveness-probe-task', 'jobs-cronjobs-mcq', 'daemonset-mcq', 'edit-deployment-basics', 'deployment-strategy-mcq'];
|
||||||
|
const NETWORKING = ['services-mcq', 'expose-service-basics'];
|
||||||
|
const CONFIGURATION = ['configmap-volume', 'resource-limits-task', 'env-vars-configmap', 'secrets-basics', 'pod-env-vars-inline'];
|
||||||
|
const TROUBLESHOOTING = ['extract-logs-basics', 'kubectl-cp-basics', 'exec-command-basics', 'node-cordon-basics', 'pod-node-assignment-mcq'];
|
||||||
|
const REAL_OPS = ['rootnode-runaway-monitor', 'broken-deployment', 'rootnode-probe-port-mismatch', 'rootnode-enforce-limits'];
|
||||||
|
|
||||||
|
let passed = 0, failed = 0;
|
||||||
|
async function test(name, fn) {
|
||||||
|
try { await fn(); console.log(` ok — ${name}`); passed++; }
|
||||||
|
catch (e) { console.error(` FAIL — ${name}\n ${e.message}`); failed++; }
|
||||||
|
}
|
||||||
|
async function completeScenario(session, scenarioId) {
|
||||||
|
const { status } = await session.request('POST', '/api/progress/record', { scenario_id: scenarioId, status: 'completed' });
|
||||||
|
assert.equal(status, 200, `completing ${scenarioId} should 200`);
|
||||||
|
}
|
||||||
|
function courseById(courses, id) { return courses.find((c) => c.course_id === id); }
|
||||||
|
function moduleById(courses, id) { for (const c of courses) { const m = c.modules.find((x) => x.module_id === id); if (m) return m; } return null; }
|
||||||
|
function findActivity(courses, id) {
|
||||||
|
for (const c of courses) for (const m of c.modules) { const a = m.activities.find((x) => x.activity_id === id); if (a) return a; }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function psql(sql) {
|
||||||
|
return execSync(`docker compose -f docker-compose.dev.yml exec -T postgres psql -U postgres -d rootnode_platform -t -c "${sql}"`, { cwd: `${__dirname}/..`, stdio: 'pipe' }).toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log('Phase 6A ROOT_ course architecture & content delivery acceptance test\n');
|
||||||
|
|
||||||
|
const owner = makeSession(GW);
|
||||||
|
await owner.request('POST', '/api/auth/instructor/login', { email: OWNER_EMAIL, password: OWNER_PASSWORD });
|
||||||
|
|
||||||
|
// ── Hierarchy, ordering, honest states ──────────────────────────────────────────────────
|
||||||
|
let structure;
|
||||||
|
await test('the ROOT_ course architecture exists with 13 courses in sequence', async () => {
|
||||||
|
const { status, body } = await owner.request('GET', `/api/admin/programs/${PROGRAM}/courses`);
|
||||||
|
assert.equal(status, 200);
|
||||||
|
assert.equal(body.length, 13);
|
||||||
|
for (let i = 1; i < body.length; i++) assert.ok(body[i].sequence > body[i - 1].sequence, 'courses must be in ascending sequence order');
|
||||||
|
structure = body;
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('courses use honest ready/partial/planned states, no fabricated content', async () => {
|
||||||
|
const plannedWithModules = structure.filter((c) => c.status === 'planned' && c.modules.length > 0);
|
||||||
|
assert.equal(plannedWithModules.length, 0, 'a PLANNED course must have zero modules, not placeholder content');
|
||||||
|
const gold = courseById(structure, 'root-10-kubernetes-troubleshooting-observability');
|
||||||
|
assert.equal(gold.status, 'partial'); // real content (gold module) alongside un-authored modules
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('the gold-standard module is fully READY with 6 ordered activities and real content', async () => {
|
||||||
|
const goldModule = moduleById(structure, 'root-10-m01-health-probes-and-troubleshooting');
|
||||||
|
assert.equal(goldModule.status, 'ready');
|
||||||
|
assert.equal(goldModule.activities.length, 6);
|
||||||
|
const types = goldModule.activities.map((a) => a.activity_type);
|
||||||
|
assert.deepEqual(types, ['lesson', 'demonstration', 'knowledge_check', 'guided_exercise', 'lab', 'reflection']);
|
||||||
|
for (let i = 1; i < goldModule.activities.length; i++) assert.ok(goldModule.activities[i].sequence > goldModule.activities[i - 1].sequence);
|
||||||
|
const lesson = goldModule.activities[0];
|
||||||
|
assert.ok(lesson.body && lesson.body.length > 500, 'lesson content must actually be loaded from Markdown, not empty');
|
||||||
|
assert.ok(lesson.instructor_notes && lesson.instructor_notes.includes('Instructor Notes'), 'instructor view must see instructor notes');
|
||||||
|
const lab = goldModule.activities.find((a) => a.activity_type === 'lab');
|
||||||
|
assert.equal(lab.scenario_id, 'rootnode-probe-port-mismatch');
|
||||||
|
assert.equal(lab.completion_behavior, 'auto_scenario');
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('the capstone activity references the existing assessment engine, not a duplicate definition', async () => {
|
||||||
|
const capstoneModule = moduleById(structure, 'root-capstone-m01-operate-and-recover');
|
||||||
|
const activity = capstoneModule.activities[0];
|
||||||
|
assert.equal(activity.activity_type, 'capstone');
|
||||||
|
assert.equal(activity.assessment_definition_id, 'rootnode-capstone');
|
||||||
|
assert.equal(activity.completion_behavior, 'auto_assessment');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── A real self-paced student, enrolled and walked through the gold module ──────────────
|
||||||
|
const { body: caseyCreate } = await owner.request('POST', '/api/admin/students', { display_name: `E2E-6A-Casey-${RUN_ID}`, login_identifier: `e2e6a-casey-${RUN_ID}` });
|
||||||
|
let casey = makeSession(GW);
|
||||||
|
await casey.request('POST', '/api/student/activate', { token: caseyCreate.activation_token, password: 'CaseyPassword123!' });
|
||||||
|
const { body: enrollCreate } = await owner.request('POST', '/api/admin/enrollments', { student_id: caseyCreate.student_id, program_id: PROGRAM, status: 'active' });
|
||||||
|
const enrollmentId = enrollCreate.enrollment_id;
|
||||||
|
|
||||||
|
let tree;
|
||||||
|
await test('a freshly-enrolled student sees the course tree with nothing complete and root-06 locked', async () => {
|
||||||
|
const { status, body } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
assert.equal(status, 200);
|
||||||
|
tree = body.courses;
|
||||||
|
const root05 = courseById(tree, 'root-05-kubernetes-foundations');
|
||||||
|
assert.equal(root05.locked, false); // the first real course is never locked
|
||||||
|
assert.equal(root05.complete, false);
|
||||||
|
const root06 = courseById(tree, 'root-06-kubernetes-application-workloads');
|
||||||
|
assert.equal(root06.locked, true, 'root-06 must be locked until root-05 is complete');
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('resume points at the first activity of the first unlocked course', async () => {
|
||||||
|
const { body } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
assert.equal(body.resume.course_id, 'root-05-kubernetes-foundations');
|
||||||
|
assert.equal(body.resume.module_id, 'root-05-m01-pods-and-kubectl-basics');
|
||||||
|
assert.equal(body.resume.activity_id, 'root-05-m01-pods-and-kubectl-basics-a01-pod-basics-mcq');
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('a student cannot mark a lab activity complete manually — only real scenario completion counts', async () => {
|
||||||
|
const { status, body } = await casey.request('POST', '/api/student/activities/root-05-m01-pods-and-kubectl-basics-a01-pod-basics-mcq/complete');
|
||||||
|
assert.equal(status, 409);
|
||||||
|
assert.equal(body.error, 'not_manually_completable');
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('completing root-05\'s 20 real scenarios marks the course complete and unlocks root-06', async () => {
|
||||||
|
for (const sid of FOUNDATION) await completeScenario(casey, sid);
|
||||||
|
const { body } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const root05 = courseById(body.courses, 'root-05-kubernetes-foundations');
|
||||||
|
assert.equal(root05.complete, true);
|
||||||
|
assert.equal(root05.percent_complete, 100);
|
||||||
|
const root06 = courseById(body.courses, 'root-06-kubernetes-application-workloads');
|
||||||
|
assert.equal(root06.locked, false, 'root-06 must unlock once root-05 is complete');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── The gold module: lesson/demo/knowledge-check/guided-exercise (manual) + lab (auto) + reflection (manual) ──
|
||||||
|
await test('lesson-only activities complete via the explicit marker, not automatically', 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 casey.request('POST', `/api/student/activities/root-10-m01-${suffix}/complete`);
|
||||||
|
assert.equal(status, 200);
|
||||||
|
}
|
||||||
|
const { body } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const goldModule = moduleById(body.courses, 'root-10-m01-health-probes-and-troubleshooting');
|
||||||
|
assert.equal(goldModule.activities.filter((a) => a.complete).length, 4);
|
||||||
|
assert.equal(goldModule.activities.find((a) => a.activity_type === 'lab').complete, false, 'the lab must not be complete yet — nothing was solved');
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('marking the same lesson complete twice is idempotent, not an error', async () => {
|
||||||
|
const { status } = await casey.request('POST', '/api/student/activities/root-10-m01-a01-lesson-health-check-concepts/complete');
|
||||||
|
assert.equal(status, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('the lab activity completes automatically from real scenario completion, not a manual marker', async () => {
|
||||||
|
await completeScenario(casey, 'rootnode-probe-port-mismatch');
|
||||||
|
const { body } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const goldModule = moduleById(body.courses, 'root-10-m01-health-probes-and-troubleshooting');
|
||||||
|
assert.equal(goldModule.activities.find((a) => a.activity_type === 'lab').complete, true);
|
||||||
|
assert.equal(goldModule.complete, false, 'the module is not complete until the reflection is also marked');
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('completing the reflection finishes the gold module and unlocks the next one', async () => {
|
||||||
|
const { status } = await casey.request('POST', '/api/student/activities/root-10-m01-a06-reflection-real-ops-takeaway/complete');
|
||||||
|
assert.equal(status, 200);
|
||||||
|
const { body } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const goldModule = moduleById(body.courses, 'root-10-m01-health-probes-and-troubleshooting');
|
||||||
|
assert.equal(goldModule.complete, true);
|
||||||
|
assert.equal(goldModule.percent_complete, 100);
|
||||||
|
const nextModule = moduleById(body.courses, 'root-10-m02-general-troubleshooting');
|
||||||
|
assert.equal(nextModule.locked, false, 'root-10-m02 must unlock once the gold module is complete');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Assessment/capstone-derived completion (auto_assessment) ────────────────────────────
|
||||||
|
await test('completing every remaining curriculum scenario and the real capstone marks the capstone activity complete', async () => {
|
||||||
|
for (const sid of [...WORKLOADS, ...NETWORKING, ...CONFIGURATION, ...TROUBLESHOOTING]) await completeScenario(casey, sid);
|
||||||
|
for (const sid of REAL_OPS) if (sid !== 'rootnode-probe-port-mismatch') await completeScenario(casey, sid); // already done above
|
||||||
|
const { status, body } = await casey.request('POST', '/api/assessments/rootnode-capstone/start');
|
||||||
|
assert.equal(status, 201, `capstone should start once every stage is complete: ${JSON.stringify(body)}`);
|
||||||
|
for (const s of body.scenarios) await completeScenario(casey, s.scenario_id);
|
||||||
|
const capstoneCheck = await casey.request('GET', '/api/capstone');
|
||||||
|
assert.equal(capstoneCheck.body.status, 'completed');
|
||||||
|
|
||||||
|
const { body: tree2 } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const capstoneActivity = findActivity(tree2.courses, 'root-capstone-m01-a01-capstone');
|
||||||
|
assert.equal(capstoneActivity.complete, true, 'the capstone course activity must derive completion from the real achievement, not a separate marker');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Persistence across logout/login (no real Lab needed — this proves the DATA persists) ──
|
||||||
|
await test('course progress survives logout and a fresh login', async () => {
|
||||||
|
await casey.request('POST', '/api/logout');
|
||||||
|
casey = makeSession(GW);
|
||||||
|
await casey.request('POST', '/api/student/login', { identifier: `e2e6a-casey-${RUN_ID}`, password: 'CaseyPassword123!' });
|
||||||
|
const { body } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const root05 = courseById(body.courses, 'root-05-kubernetes-foundations');
|
||||||
|
assert.equal(root05.complete, true, 'progress must survive a real logout/login, not just an in-memory session');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Cross-student isolation ──────────────────────────────────────────────────────────────
|
||||||
|
const { body: isolatedCreate } = await owner.request('POST', '/api/admin/students', { display_name: `E2E-6A-Isolated-${RUN_ID}`, login_identifier: `e2e6a-isolated-${RUN_ID}` });
|
||||||
|
const isolated = makeSession(GW);
|
||||||
|
await isolated.request('POST', '/api/student/activate', { token: isolatedCreate.activation_token, password: 'IsolatedPassword123!' });
|
||||||
|
const { body: isolatedEnroll } = await owner.request('POST', '/api/admin/enrollments', { student_id: isolatedCreate.student_id, program_id: PROGRAM, status: 'active' });
|
||||||
|
|
||||||
|
await test('a second student on the same program sees their own independent, empty progress', async () => {
|
||||||
|
const { body } = await isolated.request('GET', `/api/student/programs/${isolatedEnroll.enrollment_id}/courses`);
|
||||||
|
const root05 = courseById(body.courses, 'root-05-kubernetes-foundations');
|
||||||
|
assert.equal(root05.complete, false, 'a different student\'s completion must never leak across');
|
||||||
|
const root06 = courseById(body.courses, 'root-06-kubernetes-application-workloads');
|
||||||
|
assert.equal(root06.locked, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
const { body: strangerCreate } = await owner.request('POST', '/api/admin/students', { display_name: `E2E-6A-Stranger-${RUN_ID}`, login_identifier: `e2e6a-stranger-${RUN_ID}` });
|
||||||
|
const stranger = makeSession(GW);
|
||||||
|
await stranger.request('POST', '/api/student/activate', { token: strangerCreate.activation_token, password: 'StrangerPassword123!' });
|
||||||
|
await test('a student with NO enrollment anywhere cannot mark any activity complete', async () => {
|
||||||
|
const { status, body } = await stranger.request('POST', '/api/student/activities/root-10-m01-a01-lesson-health-check-concepts/complete');
|
||||||
|
assert.equal(status, 403);
|
||||||
|
assert.equal(body.error, 'not_entitled');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── RBAC: self-paced students have no cohort — requireStudentRelationshipAccess must apply ──
|
||||||
|
const { body: strayInstructor } = await owner.request('POST', '/api/admin/instructors', { email: `e2e6a-stray-${RUN_ID}@example.com`, display_name: 'Stray Instructor', role: 'instructor', password: 'StrayInstructorPass123!' });
|
||||||
|
const strayInstructorSession = makeSession(GW);
|
||||||
|
await strayInstructorSession.request('POST', '/api/auth/instructor/login', { email: `e2e6a-stray-${RUN_ID}@example.com`, password: 'StrayInstructorPass123!' });
|
||||||
|
|
||||||
|
await test('a plain instructor with no relationship to a self-paced student is forbidden from their course progress', async () => {
|
||||||
|
const { status } = await strayInstructorSession.request('GET', `/api/admin/students/${caseyCreate.student_id}/courses?program_id=${PROGRAM}`);
|
||||||
|
assert.equal(status, 403);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Note: self-paced enrollment creation is admin/owner-only (admin-programs-routes.js), so a
|
||||||
|
// plain 'instructor' can never become an enrollment's created_by for a self-paced student —
|
||||||
|
// requireStudentRelationshipAccess's positive path for a plain instructor is necessarily via
|
||||||
|
// a shared cohort, already covered by e2e-phase5c.js's equivalent notification-visibility
|
||||||
|
// tests against the same rbac.js helper. Not re-tested here to avoid duplicating that
|
||||||
|
// coverage against unrelated cohort machinery.
|
||||||
|
await test('owner/admin can see any self-paced student\'s course progress regardless of relationship', async () => {
|
||||||
|
const { status, body } = await owner.request('GET', `/api/admin/students/${caseyCreate.student_id}/courses?program_id=${PROGRAM}`);
|
||||||
|
assert.equal(status, 200);
|
||||||
|
const root05 = courseById(body, 'root-05-kubernetes-foundations');
|
||||||
|
assert.equal(root05.complete, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Draft/inactive content never leaks to students ──────────────────────────────────────
|
||||||
|
await test('a draft activity is invisible to the student endpoint but visible to instructors', async () => {
|
||||||
|
psql(`UPDATE module_activities SET visibility = 'draft' WHERE activity_id = 'root-06-m01-deployments-and-workloads-a01-deploy-nginx'`);
|
||||||
|
try {
|
||||||
|
const { body: studentView } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const workloadsModule = moduleById(studentView.courses, 'root-06-m01-deployments-and-workloads');
|
||||||
|
assert.ok(!workloadsModule.activities.some((a) => a.activity_id === 'root-06-m01-deployments-and-workloads-a01-deploy-nginx'), 'a draft activity must never appear in a student response');
|
||||||
|
const { body: instructorView } = await owner.request('GET', `/api/admin/programs/${PROGRAM}/courses`);
|
||||||
|
const workloadsModuleAdmin = moduleById(instructorView, 'root-06-m01-deployments-and-workloads');
|
||||||
|
assert.ok(workloadsModuleAdmin.activities.some((a) => a.activity_id === 'root-06-m01-deployments-and-workloads-a01-deploy-nginx'), 'instructors must still see draft content');
|
||||||
|
} finally {
|
||||||
|
psql(`UPDATE module_activities SET visibility = 'published' WHERE activity_id = 'root-06-m01-deployments-and-workloads-a01-deploy-nginx'`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await test('a draft module is invisible to students but visible to instructors', async () => {
|
||||||
|
psql(`UPDATE course_modules SET visibility = 'draft' WHERE module_id = 'root-07-m01-services-and-networking'`);
|
||||||
|
try {
|
||||||
|
const { body: studentView } = await casey.request('GET', `/api/student/programs/${enrollmentId}/courses`);
|
||||||
|
const root07 = courseById(studentView.courses, 'root-07-kubernetes-networking-config');
|
||||||
|
assert.ok(!root07.modules.some((m) => m.module_id === 'root-07-m01-services-and-networking'));
|
||||||
|
const { body: instructorView } = await owner.request('GET', `/api/admin/programs/${PROGRAM}/courses`);
|
||||||
|
const root07Admin = courseById(instructorView, 'root-07-kubernetes-networking-config');
|
||||||
|
assert.ok(root07Admin.modules.some((m) => m.module_id === 'root-07-m01-services-and-networking'));
|
||||||
|
} finally {
|
||||||
|
psql(`UPDATE course_modules SET visibility = 'published' WHERE module_id = 'root-07-m01-services-and-networking'`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Content version stability ────────────────────────────────────────────────────────────
|
||||||
|
await test('bumping a module\'s version does not break or drop its content', async () => {
|
||||||
|
psql(`UPDATE course_modules SET version = version + 1 WHERE module_id = 'root-10-m01-health-probes-and-troubleshooting'`);
|
||||||
|
const { body } = await owner.request('GET', `/api/admin/programs/${PROGRAM}/courses`);
|
||||||
|
const goldModule = moduleById(body, 'root-10-m01-health-probes-and-troubleshooting');
|
||||||
|
assert.equal(goldModule.activities.length, 6, 'a version bump must never drop activities');
|
||||||
|
assert.ok(goldModule.activities[0].body && goldModule.activities[0].body.length > 500, 'content must still load after a version bump');
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`\n${passed} passed, ${failed} failed`);
|
||||||
|
process.exit(failed ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((e) => { console.error('FATAL', e); process.exit(1); });
|
||||||
Reference in New Issue
Block a user