# RootHVN Learn and Courses parity contract

This document is the acceptance contract for replacing Sngine's course-listing feature with the RootHVN learning engine. The Replit export is the behavioral source. Existing Sngine identities, profiles, social relationships, media services, notifications, wallet and payment providers are integration services; they do not define the learner experience.

## Launch rule

The `courses` module remains `disabled` until every required row below has staged evidence. A navigation link, styled card or source-level test is not sufficient evidence. No migration enables Courses, changes an existing Sngine course post or enrolls a real account.

Utility-first does not mean courses-later in the implementation. RootHVN Learn,
teacher studios, protected media, cohorts, course-to-calendar actions and
explicit social sharing are parts of the same super app. The launch switch may
hide Courses, Community or Messaging independently, but it must preserve all
course data and must never require the global feed for learning or cohort use.

## Learner parity

- Discover and search approved published courses.
- Apply Kids Mode, minor/adult, preview and enrollment restrictions on the server.
- Display free, paid, Kids, 18+ and live labels without exposing protected meeting links.
- Save or unsave a course and show enrolled work in My Library.
- Enroll in a free course idempotently; paid enrollment must be an atomic verified order before access is granted.
- Show ordered modules, lessons and inline learning activities.
- Resume the last lesson and preserve progress.
- Play video lessons with play/pause, ten-second seeking, speed selection, captions disclosure, lesson list and Up Next.
- Complete video lessons at the Replit threshold or end-of-playback and complete article lessons explicitly.
- Support multiple-choice, long-answer, private journal and action-step activities.
- Show lesson-scoped checkpoint flashcards with term/definition reveal behavior.
- Never return journal response text to an instructor, administrator analytics response or another learner.
- Calculate progress from accessible required lessons and activities and complete the course exactly once.
- Save eligible course events to the private RootHVN calendar without making the utility record public.
- Make repeated course-plan requests idempotent so retrying cannot duplicate the same course and date.

## Instructor parity

- Unlock publishing after three completed courses unless the RootHVN owner records an audited allow/block override.
- Create a personal or authorized business-context draft.
- Edit title, subtitle, description, audience rating, delivery type and protected live-class link.
- Add, order and remove modules, lessons and activities.
- Upload cover, trailer, lesson video, download and caption assets through validated media handling.
- Enforce the 200 MB Replit video limit until a tested production transcoding policy replaces it.
- Mark a lesson as a free preview.
- Publish only a course containing at least one lesson.
- Send new and materially edited content to review; do not show it in public discovery before approval.
- Ask before sharing a published course to the social feed. Never auto-post.
- Record the audience and a one-time consent token for every share; retrying the same consent must never create a second post.
- Show enrollment, completion rate, estimated net earnings and top-lesson analytics without exposing private learner writing.
- Generate the instructor-only workbook PDF with textual lessons, activities, answer cues, checkpoint flashcards and the official RootHVN rose watermark; never include learner journal responses.

## Owner and administrator parity

- Review a pending course from a safe preview.
- Approve or reject it with an audit record and optional note.
- Notify the instructor after approval or rejection when Notifications is enabled, without weakening the review transaction if delivery fails.
- Change instructor eligibility through an audited owner control.
- Disable, maintain or enable Courses independently of the social feed.
- Keep the route, write endpoints, mobile/API paths and background jobs fail-closed while disabled.
- Review payment, refund and media-processing failures without receiving protected payment credentials.

## Cohort and social parity

- Support public, invite-only and private cohorts with open or approval-required joining.
- Support owner, moderator and member roles plus pending, active, left and removed states.
- Hide private cohort posts from non-members.
- Use Sngine posts and profiles through explicit links rather than duplicating the social graph.
- Preserve the Replit rule that only an eligible business/founder context creates a cohort.
- Connect courses to cohorts without requiring the global feed to be enabled.

## Production additions required beyond the current Replit export

- Complete paid course and paid cohort enrollment. The Replit endpoints currently report payment as unavailable.
- Process course video into a production playback format. The Replit editor uploads raw originals and contains a production transcoding TODO.
- Add verified webhook idempotency, refund reconciliation and enrollment revocation rules.
- Run real Safari/PWA and physical-device video, reminder and offline acceptance.

## Protected media implementation status

- The instructor studio now uploads course media in 5 MB chunks to an install-specific private directory outside the web root.
- The server enforces the 200 MB MP4 limit, validates declared and assembled size, extension, MIME signature, MP4 container marker, image dimensions, UTF-8 WebVTT headers and SHA-256 integrity before marking an asset ready.
- Replaced assets are quarantined for rollback rather than silently reused. A media change returns the course to pending review.
- Every media request is streamed through a signed-in controller that rechecks module, course, audience, preview, instructor/admin and enrollment access and supports single-range video playback.
- External lesson media URLs are no longer accepted by the instructor editor. Video and download lessons block publication until their protected asset is ready.
- Staging proved private-directory permissions, PHP byte-range streaming, MP4/WebVTT validation, raw-path denial and transaction/file rollback. Physical Safari playback remains a device gate before Courses can be enabled publicly.

## Course-depth implementation status

- The source candidate lets an eligible teacher choose a personal profile or one of their managed Sngine business Pages at course creation. The server independently verifies Page adminship, preserves the accountable instructor ID, and exposes a stable host identity on discovery and course pages; the host cannot be silently switched after review. Staging exercised the authorized lifecycle and a signed-mobile forged-Page submission; the latter returned exact 422 `Choose a business Page you manage.` without inserting a course. Disposable Page/course/session state was removed and Community Feed remained Disabled.
- The instructor studio now supports full curriculum maintenance: create, edit, exact reorder and remove for modules and lessons. Removing a module preserves every active lesson under Unassigned, while removing a lesson is a soft delete that unanchors activities and quarantines pending, processing or ready private media instead of exposing or silently reusing it.
- Every material curriculum mutation—including add, edit, reorder and delete for modules, lessons, activities and flashcards—locks the course row, requires the current course version, returns the course to pending review and keeps positions deterministic. Flashcard edits additionally require their own row version. The browser controls use an in-app two-press safeguard rather than Sngine's asynchronous `window.confirm` override. On staged v9, two editor tabs started at version 2; the current tab advanced to version 3, the stale version-2 add created no row, and the fixture still contained exactly the two winning modules before cleanup.
- Staging exercised module and lesson edits, a two-module reorder, module removal with lesson preservation, lesson soft deletion, fixture cleanup and owner reapproval on the exact v4 archive. The retained synthetic course returned to its original one-module/one-lesson curriculum and Courses remained disabled.
- Unpublished drafts now have a deliberately narrow cleanup path: the accountable instructor or an authorized platform admin can soft-delete only a `draft` with no enrollment records. RootHVN locks the row, requires the current course version, hides it with `deleted_at`, and quarantines any protected uploads instead of erasing audit evidence. Published/reviewed courses cannot use this shortcut.
- Lesson-scoped checkpoint flashcards now support create, edit with optimistic version checks, reorder, delete, learner reveal behavior and automatic return to pending review after instructor changes.
- Staging exercised that complete flashcard lifecycle while global Community Feed remained Disabled. `rh_test_instructor` created two disposable cards, placed B ahead of A, edited A and retained the exact value after reload. A mutation-free production-endpoint harness submitted the current course version with a stale card version and received exact 409 `version_conflict` without changing the saved row. Owner review returned to pending and was reapproved; `rh_test_member_a` then saw B ahead of A and revealed both exact definitions. The instructor deleted both disposable cards, the owner reapproved the restored single-card baseline, the public harness was removed, the canonical owner session was restored, and Courses returned to audited Disabled with its data preserved. A direct member request then failed closed at `roothvn.php?unavailable=courses`, while the owner retained the labeled disabled-module preview.
- A separate platform-administrator review pass used Sngine's native `rh_test_admin` identity to approve the clean retained course with the exact `RH ADMIN REVIEW ACCEPTANCE 2026-11-29` note. A temporary token-gated, read-only verifier matched the pending-to-approved audit transition, administrator actor, published/approved state and unchanged `Rooted priority` checkpoint card. The permanent source contract proves that review commits before notification and the notification adapter catches `Throwable`; a second token-gated runtime verifier executed that exact adapter with a transport that deliberately threw once, then confirmed course state, version and review-audit count were unchanged. All temporary verifier paths were removed and returned HTTP 404, the canonical owner session was restored, and Courses returned to audited Disabled without deleting course data. The owner/admin/audit/notification-failure review slice is complete.
- The instructor workbook is generated in memory, never written into the public uploads tree, and is restricted to the course instructor or an authorized owner/admin review. It includes course text, activity prompts, multiple-choice answer cues and checkpoint cards, but never learner response text.
- The PDF uses the existing official `logo-rose.png` artwork as a low-opacity watermark and fails closed if the host cannot prepare that official asset.
- Staged v11 produced and downloaded the authorized owner/admin workbook, which passed one-page A4 open, complete-text extraction and visual rendering. The official rose watermark was visible; article block boundaries and the ASCII footer rendered cleanly after the v11 fix; only course, instructor, answer-key and flashcard material appeared, with no learner response text.
- With Community Feed still Disabled, the owner temporarily enabled Courses under an audited reason. `rh_test_member_a` opened Learn and the retained approved course at 100% progress, direct authoring failed closed on the course editor, and the instructor workbook returned an HTTP failure rather than a file. The owner session and launch-safe Disabled course state were then restored without deleting course data.
- Under the same independent course boundary, `rh_test_instructor` opened the retained course's complete studio and the visible protected-workbook control completed a download. The canonical owner session was restored and Courses returned to audited Disabled with course data preserved.
- Protected lesson-material acceptance created a disposable non-preview Download lesson as `rh_test_instructor`. An HTML/script fixture was rejected, a valid CSV was uploaded and replaced, and owner review restored the course to approved. A temporary read-only HTTPS matrix passed 4/4 for each enrolled member, unenrolled member, accountable instructor and administrator: authorized HEAD returned private/no-store, nosniff, same-origin and range headers; an exact 17-byte range returned 206; an invalid range returned 416; and the unenrolled learner received 404 for every path without total-size disclosure. The replacement left one quarantined predecessor. The disposable lesson was soft-deleted, its active asset moved to quarantine, the retained course was resubmitted/reapproved, the public harness was removed and Courses returned to audited Disabled.
- The hostile stale curriculum-version path, enabled web authority matrix and canonical signed-mobile discovery/detail/library/teaching/action routes passed. The combined signed-mobile matrix passed 28/28, including forged business-host rejection; Disabled returned 404 for every role, enabled role-filtered reads passed, foreign editing returned 422, the instructor stale edit returned 409 and unknown actions returned 404. The router reuses the web mutation handlers; retained fixture bytes and module state were unchanged and temporary harnesses return 404 after cleanup. Full-candidate host lint and physical Safari playback remain final candidate/device gates.

## Calendar and explicit-share evidence

The retained approved synthetic instructor course passed a self-restoring production-endpoint matrix. Before any action, zero matching consent rows and feed posts existed; merely enabling Courses and Community and opening the course created no private item, consent or post. An unconfirmed share was denied without side effects. The first course-plan request created one private instructor-owned calendar event, and an exact retry returned the same item with `replayed:true`. The first confirmed friends-only share created one `rh_course_post_links` consent row and one Sngine post; retrying the exact consent token returned the same post with `replayed:true`.

Cleanup deleted the exact calendar item, consent row and post, restored Courses and Community to Disabled and Calendar to Enabled with their prior updater/reason values, restored the canonical owner session, removed the private manifest and moved the public verifier to cPanel trash. Its cache-bypassed URL returns HTTP 404. This completes the no-auto-post, explicit-consent and deterministic calendar/share replay gate.

## Evidence checklist

Each role and boundary must be exercised with unmistakable disposable staging fixtures:

1. member, instructor, RootHVN admin and canonical owner;
2. regular adult, minor and Kids Mode viewers;
3. public preview, unenrolled, enrolled, completed and refunded access;
4. draft, pending, approved, rejected, published and archived courses;
5. free, paid, prerecorded and live delivery;
6. narrow phone, installed PWA, tablet and desktop layouts;
7. online, offline cold reopen and reconnect with queued progress;
8. failed media, failed payment, duplicate request and stale-version conflict paths.

The module may be enabled only after the evidence is recorded in the release acceptance report and the rollback package has been verified.
