Skip to content

refactor(script): unexport ExecutableUnit fields#139

Merged
robbyt merged 4 commits into
mainfrom
claude/review-repo-improvements-NDaxm
May 20, 2026
Merged

refactor(script): unexport ExecutableUnit fields#139
robbyt merged 4 commits into
mainfrom
claude/review-repo-improvements-NDaxm

Conversation

@robbyt
Copy link
Copy Markdown
Owner

@robbyt robbyt commented May 18, 2026

Summary

Unexports all six fields on platform/script.ExecutableUnit (ID, CreatedAt, ScriptLoader, Compiler, Content, DataProvider). The existing getters cover every external read; construction routes through NewExecutableUnit exclusively, so external callers can no longer mutate exe.DataProvider (or any other field) mid-flight.

Breaking change (pre-1.0, landed under [Unreleased] > Changed).

Test migration

The 31 external &script.ExecutableUnit{...} literals across the three engine evaluator test packages now route through a small per-package helper newExe(t, id, content, provider) that wires a mock loader + compiler to NewExecutableUnit. This preserves the ability to inject pre-built mock content while routing through the public constructor.

One risor test case ("empty execution id") was dropped — that scenario is unreachable now that NewExecutableUnit auto-derives a non-empty ID from content.GetSource(). The corresponding evaluator-level guard (exeID == "" → "exeID is empty") is left in place across all three engines as a defensive check.

Files

  • platform/script/executableUnit.go — six fields lowercased, constructor + String + getters updated
  • platform/script/executableUnit_test.go — in-package literals/reads use lowercase fields
  • engines/{extism,risor,starlark}/evaluator/exec_helpers_test.go (new) — per-package loaderMock, compilerMock, newExe helper
  • engines/{extism,risor,starlark}/evaluator/evaluator_test.go — 31 literals replaced with newExe(...); 6 exe.DataProvider reads switched to exe.GetDataProvider(); one untestable case dropped
  • CHANGELOG.md[Unreleased] > Changed entry

Closes #91.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test -race -count=1 ./... full suite green
  • grep -rn 'script\.ExecutableUnit{' --include='*.go' . returns zero matches (no external literal constructions remain)
  • CI: SonarQube quality gate, dependency-review, Copilot review

https://claude.ai/code/session_01C61VEAmjxSnX5Xhbab8NvL


Generated by Claude Code

Unexports all six fields on platform/script.ExecutableUnit (ID, CreatedAt,
ScriptLoader, Compiler, Content, DataProvider). The existing getters
(GetID, GetCreatedAt, GetLoader, GetCompiler, GetContent, GetDataProvider)
cover all external read needs.

Construction must now route through NewExecutableUnit; mid-flight mutation
of fields like DataProvider by external callers is no longer possible.

Test migration: the 31 external `&script.ExecutableUnit{...}` literals across
the three engine evaluator test packages now route through a per-package
`newExe(t, id, content, provider)` helper that wires a mock loader+compiler
to NewExecutableUnit, preserving the ability to inject pre-built content.
One risor test case ("empty execution id") is dropped — that scenario is
unreachable now that NewExecutableUnit auto-derives an ID from content.

Closes #91.

https://claude.ai/code/session_01C61VEAmjxSnX5Xhbab8NvL
Copilot AI review requested due to automatic review settings May 18, 2026 07:12
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors platform/script.ExecutableUnit to make its core fields unexported, enforcing construction via NewExecutableUnit and access via getters, and updates engine evaluator tests accordingly. This supports the broader goal of preventing external callers from mutating execution-critical state (notably DataProvider) after construction.

Changes:

  • Unexported ExecutableUnit fields (ID, CreatedAt, ScriptLoader, Compiler, Content, DataProvider) and updated getters / String().
  • Migrated engine evaluator tests away from &script.ExecutableUnit{...} literals by introducing per-package newExe(...) helpers.
  • Added a breaking-change entry to CHANGELOG.md under [Unreleased] > Changed.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
platform/script/executableUnit.go Unexports fields and updates constructor return literal, String(), and getters.
platform/script/executableUnit_test.go Updates in-package tests to use the new unexported field names.
engines/extism/evaluator/exec_helpers_test.go Adds helper mocks and newExe(...) to build units via script.NewExecutableUnit.
engines/extism/evaluator/evaluator_test.go Replaces ExecutableUnit{...} literals with newExe(...).
engines/risor/evaluator/exec_helpers_test.go Adds helper mocks and newExe(...) (with naming to avoid local clashes).
engines/risor/evaluator/evaluator_test.go Replaces literals with newExe(...); removes now-unreachable “empty execution id” case.
engines/starlark/evaluator/exec_helpers_test.go Adds helper mocks and newExe(...) to build units via script.NewExecutableUnit.
engines/starlark/evaluator/evaluator_test.go Replaces ExecutableUnit{...} literals with newExe(...) and updates provider access.
CHANGELOG.md Documents the breaking change for ExecutableUnit field visibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread platform/script/executableUnit.go
claude added 3 commits May 18, 2026 12:48
…cutableUnit

Addresses Copilot review on #139: NewExecutableUnit now rejects a nil
scriptLoader (parallel to the existing nil-compiler check) and a nil
ExecutableContent returned by Compile (which would otherwise nil-deref
exe.GetSource() on the auto-fill path). Adds two new subtests covering
both error branches.

Updates the per-package newExe test helper to substitute a tiny stubContent
when callers pass nil, since the new post-Compile guard makes nil content
unreachable through NewExecutableUnit. Drops the now-unreachable starlark
"content nil" subtest accordingly.

https://claude.ai/code/session_01C61VEAmjxSnX5Xhbab8NvL
Trailing whitespace on the stubContent method signatures tripped gci on CI.

https://claude.ai/code/session_01C61VEAmjxSnX5Xhbab8NvL
Reverts the scriptLoader and post-Compile content nil checks per the
project's "don't validate scenarios that can't happen" guideline:

- scriptLoader == nil: panics immediately with a clear nil-pointer
  message at scriptLoader.GetReader(), which is sufficient feedback at
  the boundary.
- exe == nil from Compile: would be a Compiler-interface contract
  violation, not a state real compilers produce.

Also restores the starlark "content nil" subtest (now reachable again)
and drops the stubContent shim from each newExe helper.

https://claude.ai/code/session_01C61VEAmjxSnX5Xhbab8NvL
@sonarqubecloud
Copy link
Copy Markdown

@robbyt robbyt merged commit 6fb7723 into main May 20, 2026
3 checks passed
@robbyt robbyt deleted the claude/review-repo-improvements-NDaxm branch May 20, 2026 02:17
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.

[v1][breaking] Hide internal fields on ExecutableUnit

3 participants