Skip to content

fix(tool): take each command's target spellings in check, build and test (#589) - #593

Merged
houko merged 2 commits into
nsgo-dev:mainfrom
dhruv1220:fix/target-names-check-test-589
Nov 18, 2026
Merged

houko merged 2 commits into
nsgo-dev:mainfrom
dhruv1220:fix/target-names-check-test-589

Conversation

@dhruv1220

@dhruv1220 dhruv1220 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #589: nsgo check -target windows failed with unknown target "windows", while nsgo test -target windows takes the plain OS name — the commands spelled targets differently, so verifying a cross-platform change meant learning two vocabularies and retyping the flag.

Each command now takes the other's spelling:

  • nsgo check -target, nsgo build -target and nsgo.yaml's build.targets accept a bare OS name: windows vets/builds windows_arm64 and windows_x64, linux and macos the same, and android is android_arm64 only, as the x86_64 build needs an NDK (the same exclusion all already makes). The expansion lives in expandTargets, so all three callers agree.
  • nsgo test -target accepts an arch-qualified name: windows_x64 runs the windows target, and likewise for macOS, Linux and Android. The target is normalized once at the top of runTests, so -activate and -fps still see the plain name.
  • An unknown target in either command lists the names it accepts: check already did through expandTargets, and test now validates up front instead of surfacing vetEnv's bare unknown target from deep inside the listing step.

Also updates the three -target help texts, the Building docs (en and zh) and the nsgo skill references, and adds a CHANGELOG line. While touching skills/nsgo/references/testing.md, its nsgo test -target example dropped a stale or all: test never accepted all.

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

Screenshots

None — nothing visible changes.

Verification

  • go tool nsgo check — passed (checked catalogs, vetted, vetted the dev client)
  • go tool nsgo test ./cmd/nsgo/ — full package suite: 276 passed, 0 failed, 20 skipped
  • go tool nsgo test -target <target> on the targets above — the new TestCheckBareOSTarget vets windows and linux through the real check on this Linux host; test -target runs need a host of that OS and are covered by TestNormalizeTestTarget and TestRunTestsUnknownTargetListsNames.

New tests, all failing before the fix and passing after it:

  • TestExpandTargetsBareOS / TestExpandTargetsBareOSDropsDuplicates (cmd/nsgo/build_test.go): windows/linux/macos expand to both architectures, android to android_arm64, duplicates dropped.
  • TestCheckBareOSTarget (cmd/nsgo/check_test.go): check with windows and linux vets both architectures of each.
  • TestNormalizeTestTarget / TestRunTestsUnknownTargetListsNames (cmd/nsgo/test_test.go): arch-qualified spellings map to their OS, and an unknown test target errors listing the accepted names.

Checklist

  • The title is a Conventional Commit, such as fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.
  • Docs whose facts change are updated, and CHANGELOG.md's Unreleased has a line for a capability users can see.
  • New third-party code, assets and dependencies name their source and license. (None added.)

Review follow-up (c1c830a)

Addresses houko's review of 2026-11-18:

  • -target is normalized first, via a new checkTestTarget at the top of runTests, so -activate sees the plain name: test -target macos_arm64 -activate now works. TestActivateNeedsMacOSTarget drops all, which is not a test target and now errors as unknown.
  • normalizeTestTarget accepts only the arch-qualified names in build.go's targets, so windows_foo, macos_ and linux_riscv64 are refused with the accepted names listed.
  • A spelling whose architecture the target cannot run is refused, naming the spelling to use: a desktop target runs this machine's architecture, Android's tests always run arm64. TestCheckTestTarget covers this host-independently.
  • CHANGELOG entry now references (#593 by @dhruv1220); the os loop variables in testtarget.go and build.go are now goos.

Verification for this commit: go tool nsgo check passed; go tool nsgo test ./cmd/nsgo/ is 277 passed, 0 failed, 20 skipped, on a Linux host. The new/changed tests fail with the old normalize logic and with the arch check disabled.

@github-actions github-actions Bot added size/M documentation Improvements or additions to documentation cli and removed size/M labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown

Thanks for your first pull request! Before it is merged:

  • Write the title as a Conventional Commit, such as fix(linux): ...; a squash merge uses it as the commit subject.
  • Run go tool nsgo check and go tool nsgo test, and say in the description what you ran on which targets and what you could not.
  • Making a change says what a pull request needs, and AGENTS.md and ARCHITECTURE.md how the code is organized.

@github-actions github-actions Bot added the bug Something isn't working label Nov 17, 2026

@houko houko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for taking this on. The check/build side looks right to me: expandTargets is the single place all three callers go through, android leaving out android_x64 matches all, and the docs, help texts and skill references are updated together. The new tests pass. A few things on the test side need to change before this can go in.

1. -activate rejects an arch-qualified macOS target. runTests checks opts.activate && opts.target != "macos" before it normalizes the target, so nsgo test -target macos_arm64 -activate fails with test: -activate goes with -target macos. The PR description says -activate and -fps see the plain name, but that's only true for -fps. Normalizing first, as the very first thing in runTests, fixes it. Please add a test for this case.

2. Any suffix is accepted. normalizeTestTarget only looks at what comes before the first _, so windows_foo, macos_ and linux_riscv64 all quietly become windows, macos and linux. The issue asks for an unknown name to list the accepted names. Please accept only the names in targets from build.go, so the two commands agree on what's valid.

3. The architecture is dropped without a word. buildTargetRunner builds the desktop targets for runtime.GOARCH (testtarget.go, the macos/windows/linux cases), and Android test builds always use GOARCH=arm64. So -target windows_arm64 on an x64 Windows host runs x64 tests and reports a pass, and -target android_x64 runs arm64. If someone asks for an architecture that won't actually run, they should hear about it. Either honor it where the host can run it, or reject a name whose architecture isn't the one the target uses here and say which name to use instead. The issue's Proposal covers this: "runs the windows target on that architecture where it can, or says which name to use".

4. Changelog reference. Entries reference the pull request and its author, as in (#79 by @togotop). This one should be (#593 by @dhruv1220), not (#589 by @houko).

A small one while you're in there: testtarget.go and build.go both import os, and the new loops name a variable os, which shadows the package. goos would read better.

I ran the new tests and probed these cases on Linux at bd1c4fc: the PR's tests pass, and items 1 to 3 reproduce as described.

…nable architectures (nsgo-dev#593)

Address houko's review on nsgo-dev#593:
- runTests normalizes -target first, via a new checkTestTarget,
  so -activate sees the plain name: `test -target macos_arm64
  -activate` now works. TestActivateNeedsMacOSTarget drops
  "all", which is not a test target and now errors as unknown.
- normalizeTestTarget accepts only the arch-qualified names in
  build.go's targets, so windows_foo, macos_ and linux_riscv64
  are refused with the accepted names listed.
- A spelling whose architecture the target cannot run is
  refused, naming the spelling to use: a desktop target runs
  this machine's architecture, Android's tests always run
  arm64. TestCheckTestTarget covers this host-independently.
- CHANGELOG entry now references (nsgo-dev#593 by @dhruv1220).
- `os` loop variables in testtarget.go and build.go renamed
  to `goos`, so they no longer shadow the os package.

Both new/changed tests fail with the old normalize logic and
with the arch check disabled. `go tool nsgo check` passes;
`go tool nsgo test ./cmd/nsgo/` is 277 passed, 0 failed.
@dhruv1220

Copy link
Copy Markdown
Contributor Author

Thanks for the review — all four items plus the rename are addressed in c1c830a:

  1. Normalize first: runTests now calls a new checkTestTarget as its very first step, so -target macos_arm64 -activate works. TestActivateNeedsMacOSTarget drops all from its list — it is not a test target, so it now errors as unknown before the activate check.
  2. Only valid suffixes: normalizeTestTarget accepts an arch-qualified spelling only when the full name is in build.go's targets, so windows_foo, macos_ and linux_riscv64 are refused with the accepted names listed.
  3. Architecture is no longer dropped silently: checkTestTargetArch rejects a spelling whose architecture the target cannot run, naming the spelling to use — a desktop target runs this machine's architecture, Android's tests always run arm64. TestCheckTestTarget covers both cases host-independently (it picks the host arch from runtime.GOARCH).
  4. Changelog: now references (#593 by @dhruv1220).

Also renamed the os loop variables in testtarget.go (goListFor, normalizeTestTarget) and build.go (expandTargets) to goos.

go tool nsgo check passes; go tool nsgo test ./cmd/nsgo/ is 277 passed, 0 failed, 20 skipped. The new/changed tests fail with the old normalize logic and with the arch check disabled. I also appended a review-follow-up section to the PR description with the verification for this commit.

@houko

houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks, all four items and the rename are in. I ran go tool nsgo test ./cmd/nsgo at c1c830a on Linux x64 (285 passed, 0 failed) and probed the new errors: linux_arm64, windows_foo, android_x64 and tvos are refused with the right message, and -activate now sees the plain name.

One thing to fix: since the architecture check went in, the docs say a little more than the tool does. docs/public/en/building.md, its zh mirror, skills/nsgo/references/testing.md ("windows_x64 means windows") and the -target help in main.go all say an arch-qualified name runs its OS's target, but it now does that only for the architecture the target runs here (this machine's for desktops, arm64 for Android) and refuses the other. Please say so in all four, for example "nsgo test -target also takes the name of the architecture it runs: windows_x64 on an x64 Windows machine runs the windows target."

Optional: the architecture check runs before the host check, so on Linux -target windows_arm64 answers "the windows tests run for x64 on this machine; use -target windows", and following that gives "the windows target runs on a Windows machine". Checking the architecture only when the target's OS is the host's (runtime.GOOS), as -target macos_x64 on Linux already ends up doing, would avoid suggesting a name that cannot run either.

@houko
houko merged commit 6144c87 into nsgo-dev:main Nov 18, 2026
19 of 23 checks passed
houko added a commit that referenced this pull request Nov 18, 2026
Since #593 added checkTestTargetArch, nsgo test -target accepts an arch-qualified name only for the architecture the target runs on here (this machine's for desktops, arm64 for Android) and refuses the other, but the building guide, its zh mirror, the skill and the -target help still said any arch name simply means its OS.
houko added a commit that referenced this pull request Nov 18, 2026
Since #593 added checkTestTargetArch, nsgo test -target accepts an arch-qualified name only for the architecture the target runs on here (this machine's for desktops, arm64 for Android) and refuses the other, but the building guide, its zh mirror, the skill and the -target help still said any arch name simply means its OS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli documentation Improvements or additions to documentation size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nsgo check -target and nsgo test -target take different platform names (windows vs windows_x64)

2 participants