Skip to content

[feat] STAR-13 (BOX-06): console capture for print/log#22

Merged
vt128 merged 1 commit into
masterfrom
feat/star-13-console-capture
Jun 19, 2026
Merged

[feat] STAR-13 (BOX-06): console capture for print/log#22
vt128 merged 1 commit into
masterfrom
feat/star-13-console-capture

Conversation

@vt128

@vt128 vt128 commented Jun 19, 2026

Copy link
Copy Markdown
Member

STAR-13 / BOX-06

Add EnableConsoleCapture so a Box can collect its script's console output instead of emitting it straight to stderr.

API

  • Starbox.EnableConsoleCapture() *Console — installs the capture and returns the buffer.
  • Starbox.Console() *Console — the buffer, or nil if capture was never enabled.
  • Console.Drain() []ConsoleEntry — returns the buffered entries and clears them (per-run drain); Console.Len() reports the undrained count.
  • ConsoleEntry{Time, Level, Message, Fields} + ConsoleField{Key, Value}; LevelPrint is the level for print().

Behavior

  • print() → a LevelPrint entry (no fields).
  • log.<level>() (when the log module is loaded) → a leveled entry; keyword args are kept as structured Fields verbatim, never rendered into the message (positional args fold into the message exactly as the log module renders them).
  • A single unified buffer keeps print and log entries in script call order.
  • Capture reuses the existing print-func + logger wiring, so it takes precedence over SetPrintFunc/SetLogger; it panics if called after execution.

The log half is captured via a small zapcore.Core that records each entry into the Console, recovering raw field values without a per-type switch.

Note: the old "log.fatal kills the host" report is disproven upstream — starlet's log module maps fatal to Errorw and never calls os.Exit. The prism engine.go:104 comment fix referenced in the backlog is a separate cross-repo change, out of scope here.

Tests

console_test.go: print-only, log-with-raw-fields, interleaved order, per-run drain, not-enabled-nil. console_internal_test.go: white-box core With/Sync. Plus the after-exec panic guard in TestSetAddRunPanic. console.go coverage 100%; gofmt/go vet clean; go test -race -count=2 and the Docker golang:1.19 floor green.

EnableConsoleCapture routes a Box's console output into an in-memory,
drainable Console instead of stderr: print() becomes a LevelPrint entry,
and the log module's calls become leveled entries whose keyword arguments
are preserved as structured Fields (never pre-rendered into the message).
A single unified buffer keeps print and log entries in script call order;
Console.Drain returns and clears it for the per-run drain pattern.

Capture reuses the existing print-func and logger wiring (it sets the
machine print function and the log module's logger), so it takes precedence
over SetPrintFunc/SetLogger.

Note: the old "log.fatal kills the host" concern is disproven upstream -
starlet's log module maps fatal to Errorw and never calls os.Exit.

Tests: print-only, log with raw fields, interleaved order, per-run drain,
not-enabled nil, after-exec panic guard, and white-box core With/Sync.
@codacy-production

codacy-production Bot commented Jun 19, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 59 complexity · 4 duplication

Metric Results
Complexity 59
Duplication 4

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.08% coverage variation

Metric Results
Coverage variation +0.08% coverage variation (-1.00%)
Diff coverage 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (46b6c85) 1073 1060 98.79%
Head commit (1ffac86) 1147 (+74) 1134 (+74) 98.87% (+0.08%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#22) 74 74 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.48%. Comparing base (46b6c85) to head (1ffac86).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
+ Coverage   98.37%   98.48%   +0.11%     
==========================================
  Files          11       12       +1     
  Lines         799      859      +60     
==========================================
+ Hits          786      846      +60     
  Misses          7        7              
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vt128 vt128 merged commit 47b948a into master Jun 19, 2026
11 checks passed
@vt128 vt128 deleted the feat/star-13-console-capture branch June 19, 2026 17:54
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