Skip to content

[codex] Wire Sun context runtime deps#894

Merged
elkimek merged 1 commit into
mainfrom
codex/sun-context-runtime-deps
Jun 15, 2026
Merged

[codex] Wire Sun context runtime deps#894
elkimek merged 1 commit into
mainfrom
codex/sun-context-runtime-deps

Conversation

@elkimek

@elkimek elkimek commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add configureSunContext and a startup hook so Sun AI context helpers are wired from canonical modules instead of direct window.* reads.
  • Cache and load the new hook module from the Light/Sun startup bundle, with service-worker coverage guarded in verify-modules.
  • Update focused node/browser tests to configure and restore Sun context deps directly, and ratchet windowReferences from 1164 to 1119.

Validation

  • npm run typecheck
  • npm run quality
  • node tests/test-sun-context.js
  • npm run test:playwright -- tests/playwright/sun-context-browser-coverage.spec.js
  • ./run-tests.sh

@greptile-apps

greptile-apps Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces direct window.* reads in sun-context.js with a module-level dependency injection object (sunContextDeps) configured via the new configureSunContext() API. A new startup hook module (sun-context-hooks.js) wires all 14 real implementations from their canonical owning modules at app load time, and tests are updated to use the same API for mocking and teardown.

  • sun-context.js: Adds sunContextDeps object with safe defaults, configureSunContext() with allowlist guard and debug-mode unknown-key warning, and a _bodyRegionFractionByKey() helper; all 45+ window.* reads are replaced with sunContextDeps lookups, reducing windowReferences from 1164 → 1119.
  • sun-context-hooks.js (new): Module-level call to configureSunContext() at startup with the real implementations imported from sun.js, sun-spectrum.js, sun-uvdata.js, light-env.js, and utils.js; added to app-light-sun-modules.js, the SW cache list, and verify-modules.js.
  • Tests: Playwright and Node tests replace window.* mutation/restore with configureSunContext() calls; restoreDeps is now assigned as the first statement inside try, closing the prior state-leak window flagged in review.

Confidence Score: 5/5

Safe to merge — the window.* → dependency-injection migration is complete and the fallback values for all 14 deps match the prior code's behavior.

All production code paths in sun-context.js are correctly wired to sunContextDeps, defaults match the old window.* fallbacks, the startup hook covers every registered dep key, and the service worker cache and verify-modules assertions keep coverage honest. The two observations in test-sun-context.js are about test teardown patterns; neither affects production behavior or test correctness under current conditions.

tests/test-sun-context.js — sections 6 and 9 set deps without try/finally protection, and the unknown-dep test sets isDebugMode outside the try block. All three are minor test hygiene concerns, not bugs.

Important Files Changed

Filename Overview
js/sun-context.js Replaces all window.* reads with sunContextDeps lookups; adds configureSunContext() with allowlist guard and debug-mode warning; adds _bodyRegionFractionByKey() helper. Migration is complete and fallbacks match prior behavior.
js/sun-context-hooks.js New startup hook module; calls configureSunContext() at module evaluation time with all 14 canonical deps imported from their owning modules. All keys match sunContextDeps exactly.
js/app-light-sun-modules.js Adds import of sun-context-hooks.js to the Light/Sun startup bundle, wiring the new hook into the app startup sequence.
tests/playwright/sun-context-browser-coverage.spec.js Replaces window.* mutation with configureSunContext() calls; restoreDeps is now assigned as the very first statement inside the try block, closing the prior state-leak window.
tests/test-sun-context.js Migrates window.* stubs to configureSunContext(); adds an unknown-key warning test. Sections 6 and 9 set deps without a wrapping try/finally, leaving minor state-leak exposure if an intermediate assertion throws.
service-worker.js Adds /js/sun-context-hooks.js to APP_SHELL cache list; corresponding verify-modules.js assertion guards the coverage.
scripts/quality-baseline.json Ratchets windowReferences from 1164 to 1119, accurately reflecting the 45 window.* references removed from sun-context.js.
tests/verify-modules.js Adds assertion that the service worker caches sun-context-hooks.js, keeping coverage checks in sync with the new module.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[app-light-sun-modules.js] -->|imports| B[sun-context-hooks.js]
    B -->|imports canonical deps from| C[sun.js / sun-spectrum.js / sun-uvdata.js / light-env.js / utils.js]
    B -->|calls at module eval time| D[configureSunContext]
    D --> E{key in sunContextDeps?}
    E -->|yes| F[update sunContextDeps key]
    E -->|no| G[_debugWarn unknown key]
    G --> H{isDebugMode returns true?}
    H -->|yes| I[console.warn]
    H -->|no| J[silent skip]
    D --> K[return previous snapshot]
    L[sun-context.js] -->|exports configureSunContext| D
    L -->|exports buildSunContext| M[reads from sunContextDeps]
    O[Tests] -->|configureSunContext with mock deps| D
    O -->|configureSunContext with returned snapshot| K
Loading

Reviews (2): Last reviewed commit: "Wire Sun context runtime deps" | Re-trigger Greptile

Comment thread js/sun-context.js
Comment thread tests/playwright/sun-context-browser-coverage.spec.js
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
get-based Error Error Jun 15, 2026 3:29pm

@elkimek elkimek force-pushed the codex/sun-context-runtime-deps branch from b39a1d5 to e0f30f6 Compare June 15, 2026 15:34
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/elkimeks-projects?upgradeToPro=build-rate-limit

@elkimek elkimek merged commit b1d7e05 into main Jun 15, 2026
3 of 4 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.

1 participant