Skip to content

feat: streamline first-time setup wizard (abilityai/trinity-enterprise#49) - #1313

Merged
dolho merged 6 commits into
devfrom
feature/49-streamline-setup-wizard
Jun 23, 2026
Merged

dolho merged 6 commits into
devfrom
feature/49-streamline-setup-wizard

Conversation

@vybe

@vybe vybe commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Drops the setup-token field from first-time setup — no more copying a token from docker compose logs backend. The token machinery (ensure_setup_token/clear_setup_token/Redis-shared token + the main.py startup emission) is removed entirely; setup no longer depends on Redis (the admin write goes straight to SQLite).
  • Admin email is now required (it becomes the sign-in identity): missing → 422 at the model layer; blank/typo → 400, validated before any write so setup never half-completes. Password complexity (OWASP ASVS 2.1) is still fully enforced.
  • Rebuilds the first-run page as a welcoming, dark, branded welcome screen with an animated orbiting fleet constellation (Trinity mark core + agent nodes orbiting on three rings), split layout (stacks on mobile), prefers-reduced-motion aware. Field order: email → password (+confirm) → company (optional) → updates opt-in.

Implements abilityai/trinity-enterprise#49.

Security tradeoff (deliberate, documented)

Removing the setup token leaves the unauthenticated first-run window with no proof-of-control — on an internet-reachable instance, an attacker reaching /api/setup/admin-password before the operator finishes setup could claim the admin account. The chosen approach (per the issue's "pick one before implementing") is accept + document:

  • Documented as an operator responsibility (deploy behind a tunnel/VPN until setup completes) in docs/DEPLOYMENT.md → Security Recommendations, plus the code docstrings, the main.py startup log, architecture.md, and requirements.md.
  • The endpoint self-disables after first success (setup_completed), so exposure is the pre-setup window only; localhost/trusted-LAN is a non-issue.
  • /cso --diff ran on this branch and recorded it as F1 (HIGH, accepted/documented) — see docs/security-reports/cso-diff-2026-06-23.md. No other findings; the change removes one secret (the token) from the logs.

Changes

  • src/backend/routers/setup.py — token machinery removed; email required; set_admin_password rewritten
  • src/backend/main.py — startup token emission → plain first-run log line; import cleanup
  • src/frontend/src/views/SetupPassword.vue — full redesign (constellation animation, new field order, no token, no Redis-wait panel)
  • docs/ — DEPLOYMENT.md security note, architecture.md, requirements.md (§15.2/§43), feature-flows/first-time-setup.md
  • tests/ — removed obsolete test_1165_setup_token_shared.py; updated test_setup.py + test_setup_operator_profile.py
  • docs/security-reports/cso-diff-2026-06-23.{md,json} — security audit of this diff

Test Plan

  • tests/unit/test_setup_operator_profile.py — 7 passed (email required, blank/invalid rejection, model-layer required, no-token-field, intake gating)
  • New contract verified live against the running backend: missing email → 422; blank/invalid email → 400; weak password → 400; mismatch → 400 (instance left un-completed)
  • Real SetupPassword.vue verified rendering at http://localhost/setup (constellation + new form)
  • CI: full test_setup.py integration smoke tests (require a completed-setup instance; can't run against the local pre-setup instance without locking it)

🤖 Generated with Claude Code

Eugene Vyborov and others added 3 commits June 23, 2026 11:02
…e#49)

Drop the log-copied setup token, require an admin email, and rebuild the
first-run page as a welcoming animated welcome screen.

Backend (routers/setup.py, main.py):
- Remove the setup-token machinery entirely (ensure_setup_token /
  clear_setup_token / Redis-shared token + the main.py startup emission).
  Setup no longer depends on Redis — the admin write goes straight to SQLite.
- Make admin email REQUIRED (sign-in identity): missing -> 422 at the model
  layer; blank/typo -> 400, validated before any write so setup never
  half-completes. Password complexity (OWASP ASVS 2.1) still enforced.
- get_setup_status keeps setup_available:true for frontend back-compat.

Frontend (SetupPassword.vue):
- Full redesign: dark branded hero with an animated orbiting fleet
  constellation (Trinity mark core + agent nodes on three rings), split
  layout (stacks on mobile), prefers-reduced-motion aware.
- No setup-token field; email required; order email -> password (+confirm)
  -> company -> updates opt-in. Removed the Redis-wait panel + polling.

Security tradeoff (chosen: accept + document): removing the token leaves the
unauthenticated first-run window with no proof-of-control. Documented as an
operator responsibility (deploy behind a tunnel/VPN until setup completes) in
docs/DEPLOYMENT.md Security Recommendations; endpoint still self-disables
after first success. See docs/security-reports/cso-diff-2026-06-23.md (F1).

Docs: DEPLOYMENT.md security note, architecture.md, requirements.md
(§15.2/§43), feature-flows/first-time-setup.md.

Tests: remove obsolete test_1165_setup_token_shared.py; update test_setup.py
(no token, email required) and test_setup_operator_profile.py (email
required, model-layer + blank/invalid rejection). 7 operator-profile unit
tests pass; new contract verified live (422/400 negative paths).

Fixes abilityai/trinity-enterprise#49

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The redesigned first-run page used `position:fixed; inset:0` for its root.
On wider viewports this left a band of the light `#app` (bg-gray-100)
background showing through on the right/bottom — a fixed root is clipped to
the nearest transformed/contained ancestor instead of the viewport, so its
coverage isn't guaranteed.

Switch the root to the original component's proven normal-flow approach
(`position:relative; width:100%; min-height:100vh`), which fills the
full-width `#app`, and make the decorative aurora/grid `position:absolute`
within it. Verified covering the full viewport at 2560x1440 (light mode, the
repro case) and stacking correctly at 430px.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@dolho

dolho commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

/review — automated review of #1313

Reviewed the diff against dev (merge-base), ran the changed tests, and verified the security-critical paths. The feature is well-built and the security tradeoff is handled honestly — but there's a red CI gate that must be resolved before merge, plus a couple of scope notes.

🔴 Blocker — regression diff is failing (suite didn't really run on head)

The check isn't flaky. Its own table shows:

side total pass fail error
base 2749 2712 6 8
head 2 0 0 1

The head pytest jobs report "pass" but ran in 39s collecting 2 tests (vs base 4m30s / 2749) — a false green. The 1 error is in the PR-modified tests/test_setup.py, which is an integration/smoke test that hits a live backend (unauthenticated_client → real HTTP; it fails connect_tcp/connection-refused when no backend is up).

So either the regression-diff "head" job runs the diff-scoped tests without a backend (and your smoke-test edits now error there), or the head suite genuinely under-collected. Please:

  • get the gate green (don't merge on a 2-test head run), and
  • confirm tests/test_setup.py runs against a live backend in CI (or port the assertions to fastapi.testclient.TestClient so they're hermetic).

🟠 Security tradeoff — setup-token removal (F1 HIGH, accepted) — needs a conscious approver sign-off

This is a deliberate, documented decision and CSO --diff recorded it as F1 (HIGH, accepted). I verified the load-bearing pieces:

  • ✅ Self-disable intact: setup_completed is set (setup.py:156) and the endpoint 403s once set (:108) — exposure is the pre-setup window only.
  • ✅ Email required at the model layer (email: str = Field(...) → 422) + shape check (400); password complexity retained.
  • ✅ One fewer secret in logs (token no longer printed).

The residual risk is real: in the pre-setup window the only barrier is now network reachability + a docs note ("deploy behind a tunnel/VPN"). That's a procedural mitigation replacing a technical one (#1165/SEC-177). I'm not relitigating the accepted decision, but two asks:

  1. An approver should consciously sign off on the accepted HIGH (don't let it pass silently).
  2. Optional hardening that keeps the UX win without a docs-only control: bind the setup endpoints to loopback / a host-readable /data setup file until setup_completed, so a purely-remote attacker still can't reach POST /admin-password pre-setup. Worth a follow-up issue even if not in this PR.

🟡 Scope notes

  • VERSION bumped 0.6.1 → 0.7.0 in a feature PR. Version bumps belong to the release cut (/release), not a feature branch — and a minor bump for one feature is aggressive. Recommend dropping the VERSION change here to avoid colliding with the release process / other PRs.
  • CSO --diff report committed to the public repo (docs/security-reports/cso-diff-2026-06-23.*). Unlike a full open-vuln audit this is an accepted/documented tradeoff, so transparency is arguably the point — just flagging the public-disclosure pattern for awareness.

✅ Verified good

Summary

  • Blocker: 1 — green the regression diff gate (head ran 2 tests; test_setup.py errors without a live backend).
  • Sign-off needed: the accepted F1 HIGH (setup-token removal) — consider loopback/host-file hardening as a follow-up.
  • Scope: drop the VERSION bump.

Automated /review (correctness · CI · auth-boundary · scope). Security-critical paths verified live.

Eugene Vyborov and others added 3 commits June 23, 2026 13:32
…rrupted

The CI backend-unit regression gate runs `cd tests && pytest unit/` (the whole
unit suite). test_setup_operator_profile.py imported `routers.setup` at module
(collection) time; that import — pulling in database/dependencies/services and
their many `utils.*` leaves — failed/perturbed sys.modules during collection and
INTERRUPTED the entire `unit/` collection (head collected ~2 of 2734 → the diff
gate flagged it as a new failure).

Defer the `import routers.setup` to a cached `_get_setup()` accessor used inside
the tests, so module collection imports only stdlib/pytest/fastapi/pydantic and
can never corrupt the suite. `_get_setup()` also spec-preloads the backend
`utils.*` leaves (helpers/errors/credential_sanitizer/password_validation/
url_validation/image_optimize) the same way conftest preloads `utils.helpers`,
without touching `sys.modules["utils"]`, so the import resolves cleanly at run
time regardless of harness utils state.

Verified with the exact CI command (`cd tests && pytest unit/ --co`): the full
suite now collects 2734 items with no interruption, and the 7 setup tests pass.
No conftest changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…lint)

The previous commit's `_get_setup()` spec-preloaded backend utils leaves via
`sys.modules[...] = …` / `.pop`, which tests/lint_sys_modules.py (#762) bans
outside conftest. It's also unnecessary: in the backend-unit gate
(`cd tests && pytest unit/`), tests/unit/conftest.py already installs
src/backend/utils as the canonical `utils` package, so a plain lazy
`import routers.setup` resolves the backend `utils.*` leaves natively.

Simplify `_get_setup()` to a cached plain lazy import — no sys.modules
mutation. Verified: lint clean (no new violations), `pytest unit/ --co`
collects 2734 with no interruption, and the 7 setup tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Removing the setup token (trinity-enterprise#49) deleted
`routers/setup.py::ensure_setup_token` and the lifespan token emission, so two
#858 regression guards asserted gone behavior and failed in the backend-unit
gate:
  - test_ensure_setup_token_logs_token_via_logger_warning
  - test_lifespan_emits_setup_token_via_logger_before_event_bus

The #858 invariant itself is intact: the lifespan still emits the first-run
notice via `logger.warning` (not print), after setup_logging() and before
event_bus.start(). Replace the token-specific guard with one that matches the
new FIRST-TIME SETUP warning by content + ordering, drop the now-obsolete
ensure_setup_token guard, and remove the unused BACKEND_SETUP constant. The
Dockerfile PYTHONUNBUFFERED parity checks and the no-print-in-lifespan guard are
unchanged. 4 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@dolho

dolho commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

/review — re-review (head 9ed6ec7b)

✅ My blocker is resolved. PR is now CI-green and MERGEABLE.

regression diff now passes — and for the right reason:

side total pass fail error skip
base 2749 2712 6 8 23
head 2741 2704 6 8 23

Head pytest went from 39s / 2 tests to 4m31s / 2741 — the suite collects again. The −8 delta is exactly the obsolete test_1165_setup_token_shared.py (token machinery removed), and fail/error/skip are identical to base — no new failures, no silently-dropped coverage.

Root cause was real and the fix is clean: tests/test_setup.py imported routers.setup at collection time, flipping sys.modules["utils"] and corrupting collection for the rest of the suite (the #762 pollution class). Fixed by deferring to a lazy _get_setup() that doesn't touch sys.modules["utils"] (and it passes the #762 lint). The #858 guard was correctly updated — kept the lifespan flush-ordering assertion, just swapped token→"first-run notice".

Still outstanding (not blockers)

  • 🟠 F1 (HIGH, accepted) — setup-token removal is unchanged: no technical control was added, so the pre-setup window is still gated only by network reachability + the docs note. That's the deliberate decision — it just needs a conscious approver sign-off, and ideally a follow-up issue for the optional loopback/host-file hardening.
  • 🟡 VERSION is still bumped to 0.7.0 in this feature PR (my earlier scope note). Recommend the release cut owns version bumps; leaving it risks a collision with /release. Minor — drop it or confirm it's intentional.

Verdict: the correctness/CI blocker is cleared and the fix is sound. Merge-ready once an approver signs off on the accepted F1 HIGH and decides on the VERSION bump.

Automated /review re-review.

@dolho
dolho merged commit b9deeb7 into dev Jun 23, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants