-
Notifications
You must be signed in to change notification settings - Fork 0
feat(web): on-page verbose debug log + surface chunk tags #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Runs the web front-end's JS unit tests (node:test) on PRs and on main. | ||
| # The playground is static ES modules; its pure logic (e.g. the debug-log ring | ||
| # buffer) is unit-tested here without a browser or the wasm build. Rust/WASM | ||
| # building and the Pages deploy live in web.yml. | ||
| name: web-test | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'web/**' | ||
| - '.github/workflows/web-test.yml' | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'web/**' | ||
| - '.github/workflows/web-test.yml' | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| # Least privilege: this job only checks out and runs tests, never writes. | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| # persist-credentials: false — `npm test` runs PR-authored code, so don't | ||
| # leave the token in .git/config for it to read (zizmor: artipacked). | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| - name: Run JS unit tests | ||
| working-directory: web | ||
| run: npm test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "griff-web", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "griff WASM playground — static front-end and its JS unit tests", | ||
| "scripts": { | ||
| "test": "node --test" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Pure, DOM-free debug-log ring buffer for the playground's on-page panel. | ||
| // Kept apart from app.js so its formatting/bounding logic is unit-testable under | ||
| // `node --test` (web/test/debuglog.test.js) without a browser or the wasm glue. | ||
| // The DOM rendering stays in app.js; this owns only the lines. | ||
| // | ||
| // `max` — keep at most this many lines (oldest dropped) so the buffer is bounded. | ||
| // `now` — clock injection point; tests pass a fixed Date for deterministic stamps. | ||
| export function createDebugLog({ max = 400, now = () => new Date() } = {}) { | ||
| // A non-positive max would make slice(-max) a no-op (slice(-0) === whole | ||
| // array), silently disabling the bound — reject it so the ring stays bounded. | ||
| if (!Number.isInteger(max) || max < 1) { | ||
| throw new RangeError('createDebugLog: `max` must be a positive integer'); | ||
| } | ||
| let lines = []; | ||
|
|
||
| // One line: "HH:MM:SS label {json}". `data` is optional and JSON-stringified; | ||
| // a value that cannot be serialized is flagged rather than thrown, so logging | ||
| // never breaks the action it is tracing. | ||
| const format = (label, data) => { | ||
| const t = now().toTimeString().slice(0, 8); | ||
| let body = ''; | ||
| if (data !== undefined) { | ||
| try { body = ' ' + (typeof data === 'string' ? data : JSON.stringify(data)); } | ||
| catch (_) { body = ' [unserializable]'; } | ||
| } | ||
| return `${t} ${label}${body}`; | ||
| }; | ||
|
|
||
| const push = (label, data) => { | ||
| lines.push(format(label, data)); | ||
| if (lines.length > max) lines = lines.slice(-max); | ||
| return lines[lines.length - 1]; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| return { | ||
| push, | ||
| err: (label, data) => push('✗ ' + label, data), | ||
| clear: () => { lines = []; }, | ||
| lines: () => lines.slice(), | ||
| text: () => lines.join('\n'), | ||
| get length() { return lines.length; }, | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.