Files
rootnode-academy/infra/scripts/drills/test-phase6b-root-course-rehearsal.js
ced4568andClaude Sonnet 5 505783e5f7 test(phase6b): add ROOT curriculum acceptance coverage + real-Lab rehearsal
e2e-phase6b.js (24 checks): hierarchy for the 13 new modules across
ROOT 05-10/12/Capstone, prerequisite chains through the newly-inserted
front-door modules, lesson/knowledge-check completion in brand-new
modules, a newly-wired scenario (job-task) completing correctly, the
optional-vs-required (is_required) completion rule, persistence/
isolation/RBAC/draft-hiding proven against the new content, and the
capstone server-side unlock fix in both directions (a direct bypass
attempt rejected with blocking_stage_ids, an ordinary exam unaffected,
a legitimately unlocked attempt still accepted and its completion
reflected in the course content model).

test-phase6b-root-course-rehearsal.js + wrapper (11 checks, real k3s):
one continuous student narrative through a brand-new module (ROOT 07
Services & Service Discovery, not the Phase 6A gold module) — real Lab
launch, the Lab's own setup_commands, a real 'kubectl expose' against
the live cluster, real validate, logout/login/Resume Learning, Lab
destroy/recreate with academic progress intact — plus an instructor
narrative proving Curriculum view, Prepare Labs, and classroom/learning
tooling all still work against the expanded curriculum.

e2e-phase6a.js updated for two of this phase's own intentional,
documented behavior changes (not defects): resume now points at
root-05's new mental-model module instead of the old bare-lab bank, and
root-10's gold module now unlocks the new troubleshooting-framework
module rather than the bare-lab bank directly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-08-26 09:09:20 -05:00

196 lines
12 KiB
JavaScript

#!/usr/bin/env node
// Phase 6B §23 — the ROOT_ curriculum expansion dress rehearsal. One continuous realistic
// student narrative through a brand-NEW Phase 6B module (ROOT 07's Services & Service
// Discovery, not the Phase 6A gold module — that one already has its own rehearsal), using a
// REAL k3s Lab end to end, plus a short instructor narrative proving the Curriculum view,
// Prepare Labs, and classroom/help tooling all still work against the expanded curriculum. Same
// conventions as test-phase6a-course-rehearsal.js: assert-based, no framework, real k3s boots.
//
// Run via run-phase6b-root-course-rehearsal.sh, which brings up platform/docker-compose.dev.yml
// first.
const assert = require('assert');
const { execSync } = require('child_process');
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 SERVICES_MODULE = 'root-07-m03-services-and-service-discovery';
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 6B ROOT_ curriculum expansion 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 6B Student', login_identifier: `p6b-course-${RUN_ID}`,
});
const session = makeSession(GW);
let enrollmentId, envId;
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 in ROOT_', 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;
});
// Real Foundation completion via a real Lab, so root-06 (and therefore root-07) unlock.
const ROOT05_ALL = ['namespaces-basics', 'pod-basics-mcq', 'kubectl-essentials-mcq', 'labels-selectors-mcq', 'init-containers-mcq',
'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 ROOT06_ALL = ['deploy-nginx', 'scale-deployment', 'rolling-update-task', 'liveness-probe-task', 'jobs-cronjobs-mcq',
'daemonset-mcq', 'edit-deployment-basics', 'deployment-strategy-mcq', 'deployment-rollback'];
await step('student launches a REAL Lab and completes ROOT 05 + ROOT 06 to unlock ROOT 07\'s new Services module', async () => {
const launch = await session.request('POST', `/api/student/programs/${enrollmentId}/launch`);
assert.equal(launch.status, 200);
assert.equal(launch.body.status, 'running');
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 [...ROOT05_ALL, ...ROOT06_ALL]) {
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`);
}
// Both new teaching modules' own lesson/demo/knowledge-check/guided-exercise/reflection
// activities are manual_marker — completing only the underlying scenarios (above) is not
// enough to make root-05/root-06 COURSE-complete, which is what actually unlocks root-07.
for (const suffix of ['a01-lesson-mental-model', 'a02-demonstration-desired-state', 'a03-knowledge-check', 'a04-guided-exercise-namespaces', 'a06-reflection']) {
const r = await session.request('POST', `/api/student/activities/root-05-m00-${suffix}/complete`);
assert.equal(r.status, 200);
}
for (const suffix of ['a01-lesson-deployments', 'a02-demonstration-rollout', 'a03-knowledge-check', 'a04-guided-exercise-rollout-strategy', 'a06-reflection']) {
const r = await session.request('POST', `/api/student/activities/root-06-m02-${suffix}/complete`);
assert.equal(r.status, 200);
}
// root-06 the COURSE (root-07's actual prerequisite) also includes m03 — its two scenarios
// and two manual-marker activities.
for (const sid of ['job-task', 'cronjob-task']) {
const r = await session.request('POST', '/api/progress/record', { scenario_id: sid, status: 'completed', environment_id: envId });
assert.equal(r.status, 200);
}
for (const suffix of ['a01-lesson-jobs-cronjobs-daemonsets', 'a02-knowledge-check']) {
const r = await session.request('POST', `/api/student/activities/root-06-m03-${suffix}/complete`);
assert.equal(r.status, 200);
}
});
await step('the new ROOT 07 Services & Service Discovery module is now unlocked with real lesson content', async () => {
const { body } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
const mod = moduleFrom(body.courses, SERVICES_MODULE);
assert.equal(mod.locked, false);
assert.equal(mod.activities[0].activity_type, 'lesson');
assert.ok(mod.activities[0].body.includes('Service'), 'the real lesson content must actually be served');
});
await step('student reads the lesson/demonstration, completes the knowledge check and guided exercise', async () => {
for (const suffix of ['a01-lesson-services', 'a02-demonstration-zero-endpoints', 'a03-knowledge-check', 'a04-guided-exercise-service-type']) {
const { status } = await session.request('POST', `/api/student/activities/root-07-m03-${suffix}/complete`);
assert.equal(status, 200);
}
});
await step('student launches the module\'s Lab activity for real and runs real kubectl against it', async () => {
const { body } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
const mod = moduleFrom(body.courses, SERVICES_MODULE);
const lab = mod.activities.find((a) => a.activity_type === 'lab');
assert.equal(lab.scenario_id, 'expose-service-basics');
assert.equal(lab.complete, false);
const launch = await session.request('POST', `/api/student/programs/${enrollmentId}/launch`);
const labToken = launch.body.launch_path.match(/\/lab\/([^/]+)\//)[1];
const setup = await session.request('POST', `/lab/${labToken}/api/scenarios/expose-service-basics/setup`);
assert.equal(setup.status, 200);
// Real kubectl, run inside the student's actual disposable Lab container — solving the
// scenario the same way a real student would from the terminal, not a simulated pass.
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();
execSync(`docker exec ${containerName} kubectl expose deployment redis --name=redis-svc --port=6379`, { stdio: 'pipe' });
const validate = await session.request('POST', `/lab/${labToken}/api/scenarios/expose-service-basics/validate`);
assert.equal(validate.status, 200);
assert.equal(validate.body.passed, true, `expected the real validation to pass: ${JSON.stringify(validate.body)}`);
const record = await session.request('POST', '/api/progress/record', { scenario_id: 'expose-service-basics', status: 'completed', environment_id: envId });
assert.equal(record.status, 200);
});
await step('the lab activity completes and the module finishes once the reflection is marked', async () => {
const { body: before } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
assert.equal(moduleFrom(before.courses, SERVICES_MODULE).activities.find((a) => a.activity_type === 'lab').complete, true);
await session.request('POST', '/api/student/activities/root-07-m03-a06-reflection/complete');
const { body: after } = await session.request('GET', `/api/student/programs/${enrollmentId}/courses`);
assert.equal(moduleFrom(after.courses, SERVICES_MODULE).complete, true);
});
await step('logout, login, Resume Learning, destroy the Lab, recreate it — academic progress survives all of it', async () => {
await session.request('POST', '/api/logout');
const returning = makeSession(GW);
await returning.request('POST', '/api/student/login', { identifier: `p6b-course-${RUN_ID}`, password: 'RehearsalPass123!' });
const { body: resumed } = await returning.request('GET', `/api/student/programs/${enrollmentId}/courses`);
assert.equal(moduleFrom(resumed.courses, SERVICES_MODULE).complete, true, 'progress must survive a real logout/login');
await owner.request('DELETE', `/api/admin/environments/${envId}`);
const relaunch = await returning.request('POST', `/api/student/programs/${enrollmentId}/launch`);
assert.equal(relaunch.status, 200);
assert.equal(relaunch.body.status, 'running');
const { body: afterRecreate } = await returning.request('GET', `/api/student/programs/${enrollmentId}/courses`);
assert.equal(moduleFrom(afterRecreate.courses, SERVICES_MODULE).complete, true, 'academic progress must survive Lab destroy/recreate');
});
// ── Instructor narrative ────────────────────────────────────────────────────────────────
await step('instructor inspects the curriculum structure and this module\'s teaching notes', async () => {
const { status, body } = await owner.request('GET', `/api/admin/programs/${PROGRAM}/courses`);
assert.equal(status, 200);
const mod = moduleFrom(body, SERVICES_MODULE);
assert.equal(mod.activities.length, 6);
assert.ok(mod.activities[0].instructor_notes, 'instructor must see instructor notes the student view never does');
});
await step('instructor sees this specific student\'s real progress through the new module', async () => {
const { status, body } = await owner.request('GET', `/api/admin/students/${created.student_id}/courses?program_id=${PROGRAM}`);
assert.equal(status, 200);
assert.equal(moduleFrom(body, SERVICES_MODULE).complete, true);
});
await step('a real classroom cohort can still be prepared and observed alongside the expanded curriculum', async () => {
const cohortId = `p6b-rehearsal-cohort-${RUN_ID}`;
const create = await owner.request('POST', '/api/admin/cohorts', { cohort_id: cohortId, name: 'P6B Rehearsal Cohort' });
assert.equal(create.status, 201);
const { body: student2 } = await owner.request('POST', '/api/admin/students', { display_name: 'P6B Cohort Student', login_identifier: `p6b-cohort-student-${RUN_ID}` });
const addStudent = await owner.request('POST', `/api/admin/students/${student2.student_id}/cohort`, { cohort_id: cohortId });
assert.equal(addStudent.status, 200);
const assignCurriculum = await owner.request('POST', `/api/admin/cohorts/${cohortId}/curriculum`, { curriculum_path: 'rootnode-path' });
assert.equal(assignCurriculum.status, 200);
const prepare = await owner.request('POST', `/api/admin/cohorts/${cohortId}/prepare-labs`);
assert.equal(prepare.status, 200);
const summary = await owner.request('GET', `/api/admin/cohorts/${cohortId}/learning`);
assert.equal(summary.status, 200, 'classroom/learning tooling must still function against the expanded curriculum');
});
console.log(`\n${passed} passed, ${failed} failed`);
if (failed > 0) process.exit(1);
}
main().catch((e) => { console.error(e); process.exit(1); });