feat(publish): resolve namespace from service account token

This commit is contained in:
soarqin committed 2026-10-19 17:58:54 +08:00
1 parent 3c157d2675
commit 473c3c8fec
4 files changed
+153 -69

No files matched your search

+46 -19
View File
@@ -2,13 +2,14 @@
<#
.SYNOPSIS
Builds and publishes one mod to the Dyson Sphere Program Thunderstore community.
Resolves its Team from the service-account token before publishing.
.PARAMETER EnvFile
Optional token file. Defaults to .env in the caller's current directory when present,
otherwise TCLI_AUTH_TOKEN is read from the process environment.
.EXAMPLE
.\Publish-Mod.ps1 -Project UXAssist -Namespace soarqin -DryRun
.\Publish-Mod.ps1 -Project UXAssist -DryRun
.EXAMPLE
.\Publish-Mod.ps1 -Project Dustbin -Namespace soarqin -EnvFile C:\Secrets\thunderstore.env
.\Publish-Mod.ps1 -Project Dustbin -EnvFile C:\Secrets\thunderstore.env
#>
[CmdletBinding()]
param(
@@ -16,10 +17,6 @@ param(
[ValidatePattern('^[A-Za-z0-9_][A-Za-z0-9_.-]*\z')]
[string]$Project,
[Parameter(Mandatory = $true)]
[ValidatePattern('^[A-Za-z0-9_]+\z')]
[string]$Namespace,
[string]$EnvFile,
[switch]$DryRun
)
@@ -180,6 +177,30 @@ function Get-PublishUserToken {
return [Environment]::GetEnvironmentVariable('TCLI_AUTH_TOKEN', 'User')
}
function Get-PublishNamespace {
param([string]$Token)
$endpoint = 'https://thunderstore.io/api/experimental/current-user/'
try {
# Keep credentials on the fixed HTTPS endpoint and out of diagnostics.
$profile = Invoke-RestMethod -Uri $endpoint -Method Get -Headers @{ Authorization = "Bearer $Token" } -TimeoutSec 30 -MaximumRedirection 0 -ErrorAction Stop
} catch {
throw "Cannot query the token's Team at $endpoint. Check the service-account token, connectivity, and server availability before retrying; nothing was uploaded."
}
$username = Get-PublishJsonProperty $profile 'username'
$teamsProperty = if ($null -ne $profile) { $profile.PSObject.Properties['teams'] }
if ($username -isnot [string] -or [string]::IsNullOrWhiteSpace($username) -or
$null -eq $teamsProperty -or $teamsProperty.Value -isnot [array]) {
throw 'The current-user endpoint returned an unauthenticated or malformed response. Check the service-account token before publishing.'
}
$teams = $teamsProperty.Value
if ($teams.Count -eq 0) { throw 'The service-account token has no active Team. Check its Team membership before publishing.' }
if ($teams.Count -ne 1) { throw 'The token belongs to multiple Teams; publication requires exactly one Team.' }
if ($teams[0] -isnot [string] -or $teams[0] -notmatch '^[A-Za-z0-9_]+\z') {
throw 'The current-user endpoint returned an invalid Team name. Nothing was uploaded.'
}
return $teams[0]
}
function Assert-PublishChangelog {
param([string]$Text, [string]$Version)
$sections = @([regex]::Matches($Text, '(?is)<details\b[^>]*>(.*?)</details>') | ForEach-Object { $_.Groups[1].Value })
@@ -268,9 +289,9 @@ function Assert-PublishVersionAvailable {
}
function Invoke-ModPublish {
param([string]$RepositoryRoot, [string]$Project, [string]$Namespace, [string]$EnvFile, [switch]$DryRun)
if ($Project -notmatch '^[A-Za-z0-9_][A-Za-z0-9_.-]*\z' -or $Namespace -notmatch '^[A-Za-z0-9_]+\z') {
throw 'Supply one top-level -Project directory name and a non-empty alphanumeric/underscore -Namespace.'
param([string]$RepositoryRoot, [string]$Project, [string]$EnvFile, [switch]$DryRun)
if ($Project -notmatch '^[A-Za-z0-9_][A-Za-z0-9_.-]*\z') {
throw 'Supply one top-level -Project directory name.'
}
$projectDir = Join-Path $RepositoryRoot $Project
$projectPath = Join-Path $projectDir "$Project.csproj"
@@ -287,6 +308,7 @@ function Invoke-ModPublish {
$packageName = Get-PublishJsonProperty (Read-PublishJson $manifestPath) 'name'
if ($packageName -isnot [string] -or $packageName -notmatch '^[A-Za-z0-9_]+\z') { throw 'The manifest must have a valid, non-empty string name.' }
$token = $null
$namespace = $null
# Resolve token files before changing to the repository's build directory.
if (-not $DryRun) { $token = Get-PublishToken $EnvFile }
$oldToken = [Environment]::GetEnvironmentVariable('TCLI_AUTH_TOKEN', 'Process')
@@ -296,7 +318,10 @@ function Invoke-ModPublish {
Push-Location -LiteralPath $RepositoryRoot
try {
$null = Get-Command dotnet -CommandType Application -ErrorAction Stop
if (-not $DryRun) { Assert-PublishTcli }
if (-not $DryRun) {
Assert-PublishTcli
$namespace = Get-PublishNamespace $token
}
$metadata = Get-PublishProject $projectPath
$properties = $metadata.Properties
if (-not [string]::IsNullOrEmpty($properties.PackPreloaderTargetDir)) { throw 'Select a main mod; this project is a preloader or helper.' }
@@ -340,6 +365,12 @@ function Invoke-ModPublish {
if ($hasChangelog) { $files['CHANGELOG.md'] = Join-Path $projectDir 'CHANGELOG.md' }
Assert-PublishArchive $zipPath $packageName $version $files $hasChangelog
$teamLabel = if ($DryRun) { 'not queried (resolved from token when publishing)' } else { $namespace }
Write-Host "Project: $Project | Team: $teamLabel | Package: $packageName | Version: $version"
Write-Host 'Community: dyson-sphere-program | Categories: empty (retain existing listing categories)'
Write-Host "ZIP: $zipPath"
if ($DryRun) { Write-Host 'Dry run complete. Package validated; Team lookup and upload were skipped.'; return }
$configDir = Join-Path $configBase ([Guid]::NewGuid().ToString('N'))
$null = [IO.Directory]::CreateDirectory($configDir)
$configPath = Join-Path $configDir 'thunderstore.toml'
@@ -348,7 +379,7 @@ function Invoke-ModPublish {
schemaVersion = "0.0.1"
[package]
namespace = "$Namespace"
namespace = "$namespace"
name = "$packageName"
versionNumber = "$version"
@@ -361,17 +392,13 @@ communities = ["dyson-sphere-program"]
categories = []
"@
[IO.File]::WriteAllText($configPath, $configText + [Environment]::NewLine, [Text.UTF8Encoding]::new($false))
Write-Host "Project: $Project | Team: $Namespace | Package: $packageName | Version: $version"
Write-Host 'Community: dyson-sphere-program | Categories: empty (retain existing listing categories)'
Write-Host "ZIP: $zipPath"
Write-Host ('dotnet tool run tcli -- publish --config-path "{0}" --file "{1}"' -f $configPath, $zipPath)
if ($DryRun) { Write-Host 'Dry run complete. Package validated; no upload was attempted.'; return }
Assert-PublishVersionAvailable $Namespace $packageName $version
Assert-PublishVersionAvailable $namespace $packageName $version
[Environment]::SetEnvironmentVariable('TCLI_AUTH_TOKEN', $token, 'Process')
try { Invoke-PublishDotNet -Arguments @('tool', 'run', 'tcli', '--', 'publish', '--config-path', $configPath, '--file', $zipPath) -Secret $token }
catch { throw "Publication did not finish successfully. Inspect https://thunderstore.io/c/dyson-sphere-program/p/$Namespace/$packageName/v/$version/ before retrying; a submission may already have succeeded." }
Write-Host "Published: https://thunderstore.io/c/dyson-sphere-program/p/$Namespace/$packageName/"
catch { throw "Publication did not finish successfully. Inspect https://thunderstore.io/c/dyson-sphere-program/p/$namespace/$packageName/v/$version/ before retrying; a submission may already have succeeded." }
Write-Host "Published: https://thunderstore.io/c/dyson-sphere-program/p/$namespace/$packageName/"
} finally {
# PowerShell converts $null to an empty string for this .NET call.
# Modern runtimes preserve empty environment values; use a true null.
@@ -390,7 +417,7 @@ categories = []
}
try {
Invoke-ModPublish -RepositoryRoot $PSScriptRoot -Project $Project -Namespace $Namespace -EnvFile $EnvFile -DryRun:$DryRun
Invoke-ModPublish -RepositoryRoot $PSScriptRoot -Project $Project -EnvFile $EnvFile -DryRun:$DryRun
} catch {
Write-Error -Message $_.Exception.Message -ErrorAction Continue
exit 1
+8 -8
View File
@@ -77,21 +77,21 @@ Use Windows PowerShell 5.1 or PowerShell 7, a .NET SDK with MSBuild 17.8 or newe
dotnet tool restore
```
Select a single main mod with `-Project` and supply its Thunderstore Team with the required `-Namespace` parameter. Package Name comes from `<Project>/package/manifest.json`; version comes from the project file. Preview the build and package without a token or upload:
Select a single main mod with `-Project`. Package Name comes from `<Project>/package/manifest.json`; version comes from the project file. For publication, the script queries Thunderstore's `/api/experimental/current-user/` endpoint with the service-account token and uses its single Team as the namespace. Missing, invalid, or multiple Teams and request failures stop publication before building. Preview the build and package without a token or network access:
```powershell
.\Publish-Mod.ps1 -Project UXAssist -Namespace soarqin -DryRun
.\Publish-Mod.ps1 -Project UXAssist -DryRun
```
To publish, put a Team service-account token in a UTF-8 `.env` file in the directory where the command is invoked, then run the same command without `-DryRun`. If `.env` is absent, the script reads the process environment variable `TCLI_AUTH_TOKEN`. To select another file, pass `-EnvFile`:
```powershell
.\Publish-Mod.ps1 -Project Dustbin -Namespace soarqin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
.\Publish-Mod.ps1 -Project Dustbin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
```
The file accepts one `TCLI_AUTH_TOKEN=...` assignment, optional quotes, blank lines, and full-line comments. Token selection follows this order: explicit `-EnvFile`, the caller directory's `.env`, then the process variable. A selected file with an invalid or missing token is an error. `.env` and `.env.*` are ignored by Git; keep real tokens out of version control and shell command history. tcli 0.2.4 prioritizes a persisted Windows User-scoped token over the process token; if the values conflict, the script stops so that the stale setting can be reconciled.
The script always uses Release builds and the existing `ZipMod` target. It refreshes bundled preloaders before packaging, validates the exact ZIP, rejects an already published version, and uploads only the selected main mod. `-DryRun` still creates normal build/package outputs but skips remote version checks and uploads. Publication always targets **Dyson Sphere Program** (`dyson-sphere-program`) with empty Category input, preserving the existing listing's categories; a first release starts without categories. Versions are never bumped automatically. After an interrupted or failed submission, check the printed version page before retrying because the release may already exist.
The script always uses Release builds and the existing `ZipMod` target. It refreshes bundled preloaders before packaging, validates the exact ZIP, rejects an already published version, and uploads only the selected main mod. `-DryRun` still creates normal build/package outputs but skips credential loading, Team lookup, remote version checks, and uploads; its Team remains unresolved until publication. Publication always targets **Dyson Sphere Program** (`dyson-sphere-program`) with empty Category input, preserving the existing listing's categories; a first release starts without categories. Versions are never bumped automatically. After an interrupted or failed submission, check the printed version page before retrying because the release may already exist.
Run the focused script checks with `powershell.exe -NoProfile -File tools/tests/Test-PublishMod.ps1` or `pwsh -NoProfile -File tools/tests/Test-PublishMod.ps1`. They use synthetic credentials and stubbed network/publication commands; scratch files stay under `UXAssist/obj/publish-mod-check`.
@@ -103,20 +103,20 @@ Run the focused script checks with `powershell.exe -NoProfile -File tools/tests/
dotnet tool restore
```
通过 `-Project` 选择一个主 mod,通过必填参数 `-Namespace` 指定 Thunderstore Team。Package Name 读取 `<Project>/package/manifest.json`,版本读取项目文件。可以先预览构建和打包,无需 token,也不会上传:
通过 `-Project` 选择一个主 mod。Package Name 读取 `<Project>/package/manifest.json`,版本读取项目文件。正式发布时,脚本使用服务账号 token 查询 Thunderstore 的 `/api/experimental/current-user/` 接口,将返回的唯一 Team 作为 namespace。没有 Team、Team 名称无效、存在多个 Team 或请求失败时,脚本会在构建前停止。可以先预览构建和打包,无需 token,也无需联网:
```powershell
.\Publish-Mod.ps1 -Project UXAssist -Namespace soarqin -DryRun
.\Publish-Mod.ps1 -Project UXAssist -DryRun
```
正式发布时,将 Team 服务账号的 token 写入调用目录下的 UTF-8 `.env` 文件,再去掉 `-DryRun` 执行。如果 `.env` 不存在,脚本会读取进程环境变量 `TCLI_AUTH_TOKEN`。也可以通过 `-EnvFile` 指定其他文件:
```powershell
.\Publish-Mod.ps1 -Project Dustbin -Namespace soarqin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
.\Publish-Mod.ps1 -Project Dustbin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
```
文件允许一条 `TCLI_AUTH_TOKEN=...` 赋值,以及可选的引号、空行和整行注释。token 的读取优先级为:显式 `-EnvFile`、调用目录下的 `.env`、进程环境变量。选中的文件缺少 token 或格式无效时,脚本会报错。`.env` 和 `.env.*` 已加入 Git 忽略规则;真实 token 不应提交到版本控制,也不要写入 shell 命令历史。tcli 0.2.4 会优先读取 Windows 持久化的用户级 token;如果它与本次选定的 token 不同,脚本会停止,需先处理旧设置。
脚本始终使用 Release 构建和现有的 `ZipMod` 目标。它会在打包前更新附带的 preloader,检查本次生成的确切 ZIP,拒绝重复发布已有版本,并且只上传选定的主 mod。`-DryRun` 仍会生成正常的构建和打包产物,但跳过远程版本检查和上传。发布社区固定为 **Dyson Sphere Program**(`dyson-sphere-program`);Category 输入留空,保留已有条目的分类,首次发布则不设置分类。脚本不会自动修改版本号。提交中断或失败后,应先检查输出的版本页面,再决定是否重试,因为该版本可能已经发布成功。
脚本始终使用 Release 构建和现有的 `ZipMod` 目标。它会在打包前更新附带的 preloader,检查本次生成的确切 ZIP,拒绝重复发布已有版本,并且只上传选定的主 mod。`-DryRun` 仍会生成正常的构建和打包产物,但跳过凭据读取、Team 查询、远程版本检查和上传;Team 留待正式发布时确定。发布社区固定为 **Dyson Sphere Program**(`dyson-sphere-program`);Category 输入留空,保留已有条目的分类,首次发布则不设置分类。脚本不会自动修改版本号。提交中断或失败后,应先检查输出的版本页面,再决定是否重试,因为该版本可能已经发布成功。
可以运行 `powershell.exe -NoProfile -File tools/tests/Test-PublishMod.ps1` 或 `pwsh -NoProfile -File tools/tests/Test-PublishMod.ps1` 检查脚本。测试使用虚构的凭据,以及模拟的网络和发布命令;临时文件保存在 `UXAssist/obj/publish-mod-check` 下。
+23 -20
View File
@@ -10,13 +10,13 @@ This proposal covers a local PowerShell command. It does not add a GitHub Action
## Metadata source
Use the existing `<Project>/package/manifest.json` for package metadata. Read Team from the required `-Namespace` parameter and Package Name from the manifest's `name` field. Keep the manifest's existing schema; no additional package metadata file or Team field is needed.
Use the existing `<Project>/package/manifest.json` for package metadata. Query Team from the service-account token and read Package Name from the manifest's `name` field. Keep the manifest's existing schema; no additional package metadata file or Team field is needed.
Pass the supplied namespace to tcli as its package namespace. Require an explicit, non-empty value on every invocation, including `-DryRun`; do not default to `soarqin` or infer Team from other metadata. The service-account token must have permission to publish under the selected Team.
For publication, send the selected token as `Authorization: Bearer <token>` to `GET https://thunderstore.io/api/experimental/current-user/`. Require an authenticated profile with a non-empty username and a `teams` array containing exactly one valid Team name. Preserve that name's capitalization as tcli's namespace. Stop on an unauthenticated or malformed response, an empty or ambiguous Team list, invalid names, HTTP errors, or network failures. Do not guess a namespace or select the first of multiple Teams. `-DryRun` skips credentials and all Thunderstore requests, leaving Team unresolved until publication.
| Publishing value | Source and rule |
| --- | --- |
| Team / tcli package namespace | Required `-Namespace` parameter; non-empty and preserving capitalization. |
| Team / tcli package namespace | The selected token's unique Team from the current-user API, preserving capitalization; unresolved in `-DryRun`. |
| Package Name | `manifest.json.name`, preserving capitalization. |
| Version | Evaluated `.csproj` `Version`; `ZipMod` synchronizes `manifest.json.version_number`. Check the packaged value afterward. |
| Community | Constant `dyson-sphere-program`. |
@@ -28,21 +28,20 @@ Pass the supplied namespace to tcli as its package namespace. Require an explici
```powershell
# Publish using the caller directory's .env, or TCLI_AUTH_TOKEN if no file exists.
.\Publish-Mod.ps1 -Project UXAssist -Namespace soarqin
.\Publish-Mod.ps1 -Project UXAssist
# Read the token from an explicitly selected file.
.\Publish-Mod.ps1 -Project Dustbin -Namespace soarqin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
.\Publish-Mod.ps1 -Project Dustbin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
# Build and inspect the package without uploading; a token is not required.
.\Publish-Mod.ps1 -Project UXAssist -Namespace soarqin -DryRun
.\Publish-Mod.ps1 -Project UXAssist -DryRun
```
| Parameter | Behavior |
| --- | --- |
| `-Project <string>` | Required. Select one top-level project by directory name, such as `UXAssist` or `Dustbin`. Resolve paths from `$PSScriptRoot`, independently of the caller's current directory. |
| `-Namespace <string>` | Required. Select the Thunderstore Team. Reject empty, whitespace-only, or invalid identifiers; preserve capitalization and use this value in tcli configuration and package-version lookups. |
| `-EnvFile <path>` | Optional. Read `TCLI_AUTH_TOKEN` from an explicitly selected file. When omitted, use `.env` in the caller's current directory if present, otherwise use the process variable. |
| `-DryRun` | Build, package, validate, and show the intended publish command and metadata. Skip token requirements, remote package checks, and tcli publication. This mode still writes normal build and package outputs. |
| `-DryRun` | Build, package, validate, and show local package metadata with Team unresolved. Skip credential loading, Team lookup, remote package checks, generated tcli configuration, and publication. This mode still writes normal build and package outputs. |
Use Release configuration. Omit package-name, category, community, version-override, publish-all, and skip-build parameters from the initial interface. Selecting a preloader or helper project directly must fail with an actionable message identifying the main mod where applicable.
@@ -50,14 +49,14 @@ Target Windows PowerShell 5.1 and PowerShell 7. The existing packaging targets i
## Build and publish sequence
1. Resolve the named project within the repository. Require `<Project>/<Project>.csproj`, `package/manifest.json`, `package/icon.png`, and `README.md`. Reject traversal, wildcard input, helpers, and projects with `PackPreloaderTargetDir` set. Validate `-Namespace` and the manifest's `name` before building.
1. Resolve the named project within the repository. Require `<Project>/<Project>.csproj`, `package/manifest.json`, `package/icon.png`, and `README.md`. Reject traversal, wildcard input, helpers, and projects with `PackPreloaderTargetDir` set. Validate the manifest's `name` before building.
2. Evaluate Release MSBuild properties instead of guessing output paths or parsing only literal XML: `Version`, `ProjectName`, `TargetPath`, `PackHasChangelog`, `PackUsePluginsLayout`, and `PackPreloaderTargetDir`. Read evaluated `ProjectReference` items to find bundled preloaders. MSBuild 17.8 or newer provides the required `-getProperty` and `-getItem` JSON output.
3. For a real publish, resolve the token before changing to the repository's build directory and check the pinned local tcli tool before the expensive build. tcli 0.2.4 returns exit code 1 even when `--version` successfully prints its version: accept 0 or 1 only for this check, and require recognizable version output. For `-DryRun`, neither a token nor an installed tcli tool is required. Restore project NuGet assets when missing, then use `--no-restore` for packaging.
3. For a real publish, resolve the token before changing to the repository's build directory, check the pinned local tcli tool, and resolve its unique Team before the expensive build. tcli 0.2.4 returns exit code 1 even when `--version` successfully prints its version: accept 0 or 1 only for this check, and require recognizable version output. For `-DryRun`, neither a token nor an installed tcli tool is required and no Thunderstore requests are made. Restore project NuGet assets when missing, then use `--no-restore` for packaging.
4. For each referenced preloader whose evaluated `PackPreloaderTargetDir` belongs to the selected mod's package, run `CopyToParentPackage` in Release before packaging the main mod. This refreshes Dustbin's bundled preloader even if an old DLL already exists under `package/patchers`. Do not upload preloaders or referenced mods separately.
5. Run `dotnet build <Project>/<Project>.csproj -t:ZipMod -c Release --no-restore`. Check every native command's exit code; builds and publication must stop immediately on a nonzero result. Retain the existing warning policy.
6. Select the exact ZIP path defined by the existing target: `<Project>/package/<ProjectName>-<Version>.zip`. Do not select the newest ZIP by timestamp or a wildcard. Read the ZIP and check its root manifest identity and version, required root files, 256x256 PNG icon, expected DLL layout, and optional changelog. Compare bundled main/preloader DLLs with the current evaluated build outputs. When a separate changelog is included, require its latest English and Chinese headings to match the project version. Do not change any version automatically.
7. Write a generated, non-secret tcli configuration under `<Project>/obj/thunderstore-publish/<run-id>/thunderstore.toml`. Print the project, Team, Package Name, version, community, ZIP path, and category-preservation behavior. In `-DryRun`, stop successfully here and retain the ZIP for inspection.
8. Before a real upload, query the exact package-version endpoint using the supplied namespace, manifest package name, and evaluated project version. If the version exists, stop without uploading. Treat only HTTP 404 as an absent version; authentication, network, server, and response-format errors must remain errors. Do not automatically increment versions or retry a publish with an uncertain result.
7. Print the project, Team, Package Name, version, community, ZIP path, and category-preservation behavior. In `-DryRun`, identify Team as unresolved, stop successfully, and retain the ZIP for inspection. Otherwise, write generated, non-secret tcli configuration under `<Project>/obj/thunderstore-publish/<run-id>/thunderstore.toml` with the resolved Team.
8. Before a real upload, query the exact package-version endpoint using the resolved namespace, manifest package name, and evaluated project version. If the version exists, stop without uploading. Treat only HTTP 404 as an absent version; authentication, network, server, and response-format errors must remain errors. Do not automatically increment versions or retry a publish with an uncertain result.
9. Provide the token to the tcli child process and run `dotnet tool run tcli -- publish --config-path <generated-config> --file <exact-zip>`. Restore process environment and working directory in `finally`. Remove only this invocation's generated configuration directory after verifying its resolved path. Preserve the ZIP.
10. Return success only after tcli reports successful publication. Show the package page and tcli's download URL. After a submission timeout or failure, explain how to inspect the exact version before retrying; a failed command does not prove that the server created no release.
@@ -94,7 +93,7 @@ communities = ["dyson-sphere-program"]
categories = []
```
Generate `namespace` from `-Namespace`, `name` from `package/manifest.json.name`, and `versionNumber` from the evaluated project version. The values above illustrate `-Project UXAssist -Namespace soarqin`; they are not defaults. Validate permitted identifier/version characters before writing TOML, and pass command arguments as an array rather than composing executable PowerShell text. `[build].outdir` satisfies tcli's publish-time configuration validation; `--file` prevents tcli from building a second ZIP. The uploaded archive supplies the actual package description, dependencies, website, and other manifest content.
Generate `namespace` from the token's unique Team, `name` from `package/manifest.json.name`, and `versionNumber` from the evaluated project version. The values above illustrate `-Project UXAssist` when the token resolves to Team `soarqin`; they are not defaults. Validate permitted identifier/version characters before writing TOML, and pass command arguments as an array rather than composing executable PowerShell text. `[build].outdir` satisfies tcli's publish-time configuration validation; `--file` prevents tcli from building a second ZIP. The uploaded archive supplies the actual package description, dependencies, website, and other manifest content.
`categories = []` is deliberate. In tcli 0.2.4, omitting the setting leaves example `riskofrain2` categories from the configuration model. An empty array produces empty legacy categories and an empty per-community category map. The inspected Thunderstore server code only adds categories when the submitted list is non-empty, so an existing listing retains its current categories. Categories belong to the community listing, rather than an individual package version. A first release has no previous categories to inherit and starts without categories. No category lookup or local category cache is necessary.
@@ -112,23 +111,26 @@ Read it as UTF-8 data. Support blank lines, full-line comments, and an optional
Allow local environment files inside or outside the checkout. Keep `.env` and `.env.*` ignored by Git so that a repository-local `.env` remains untracked. Use only synthetic tokens in implementation checks.
Use the same selected token for the read-only current-user request and tcli publication. Send the Bearer header only to the fixed Thunderstore HTTPS endpoint with redirects disabled and a bounded timeout. Do not forward it to the public package-version endpoint or include response bodies, headers, or underlying request exceptions in credential-related errors.
The pinned tcli version has a Windows-specific behavior: it reads the persisted User-scoped `TCLI_AUTH_TOKEN` before the process value. Before publication, compare that User-scoped value with the selected token without logging either value. If a different non-empty User value exists, stop and explain that the caller must remove or reconcile the stale setting. Do not change User or Machine environment variables automatically. Otherwise, temporarily set only the process variable immediately around tcli invocation and restore its original presence and value in `finally`.
## Implementation work
- [x] Implement required `-Project` and `-Namespace` parameters. Read Package Name from the existing manifest and verify that it agrees with the archive manifest.
- [x] Implement required `-Project` and automatically resolve the token's unique Team. Read Package Name from the existing manifest and verify that it agrees with the archive manifest.
- [x] Add the pinned `.config/dotnet-tools.json`, the `Publish-Mod.ps1` entry point, and environment-file ignore patterns. Keep packaging logic in the existing MSBuild targets.
- [x] Add a short English/Chinese publishing section to the root README covering tool restoration, project and namespace selection, credential sources, category retention, and `-DryRun`.
- [x] Add a short English/Chinese publishing section to the root README covering tool restoration, project selection, automatic Team resolution, credential sources, category retention, and `-DryRun`.
- [x] Verify local preparation and failure handling without making a real upload. Leave mod versions, release changelogs, runtime code, `AGENTS.md`, and GitHub Actions unchanged.
## Acceptance checks
| Check | Expected result |
| --- | --- |
| `UXAssist -Namespace soarqin -DryRun`, invoked from another directory | Uses repository-relative inputs, produces the normal flat ZIP, and shows the correct identity and DSP community without requiring a token. |
| `Dustbin -Namespace soarqin -DryRun` with an existing preloader DLL | Refreshes `DustbinPreloader`, packages `plugins/` and `patchers/`, and includes the current build outputs. |
| A different explicit namespace for the same project | Uses that Team in generated configuration, version lookups, and package links while continuing to read Package Name from the existing manifest. |
| Missing project, malformed metadata, missing/empty/invalid namespace, preloader/helper selection, or traversal input | Stops before publication and identifies the invalid input. |
| `UXAssist -DryRun`, invoked from another directory | Uses repository-relative inputs, produces the normal flat ZIP, and shows local identity, unresolved Team, and DSP community without loading credentials or making Thunderstore requests. |
| `Dustbin -DryRun` with an existing preloader DLL | Refreshes `DustbinPreloader`, packages `plugins/` and `patchers/`, and includes the current build outputs. |
| The token resolves to a different Team for the same project | Preserves that Team's name in generated configuration, version lookups, and package links while continuing to read Package Name from the existing manifest. |
| Team lookup returns an anonymous/malformed profile, no Teams, multiple Teams, an invalid name, or a request error | Stops before building or publication without guessing a namespace or exposing the token. |
| Missing project, malformed metadata, preloader/helper selection, or traversal input | Stops before publication and identifies the invalid input. |
| Explicit `-EnvFile`, default caller-directory `.env`, and process token are all available | Uses the explicit file first; without it, uses the caller's `.env`; without either file, uses the process variable. Repository-local `.env` files are supported. |
| Missing token, missing explicit file, malformed selected file, or conflicting Windows User-scoped token | Stops without exposing credentials or changing persisted environment variables. |
| tcli version check prints a version with exit code 1, returns no version, or cannot start | Accepts the documented version-output case only; missing/invalid output and startup failures stop before building or publication. |
@@ -141,7 +143,7 @@ Use focused command stubs for publication/error-path checks with a synthetic tok
## Verified upstream behavior
Sources checked on 2026-10-17; command entry point checked on 2026-10-18:
Sources checked on 2026-10-17; command entry point checked on 2026-10-18; Team lookup checked on 2026-10-19:
- [tcli publishing and authentication documentation](https://github.com/thunderstore-io/thunderstore-cli/wiki): `TCLI_AUTH_TOKEN`, namespace, and publishing an existing ZIP with `--file`.
- [NuGet tcli versions](https://api.nuget.org/v3-flatcontainer/tcli/index.json): currently available tool versions.
@@ -149,5 +151,6 @@ Sources checked on 2026-10-17; command entry point checked on 2026-10-18:
- [tcli 0.2.4 configuration model](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Models/ThunderstoreProject.cs) and [upload metadata](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Configuration/Config.cs): category defaults, the empty-array mapping, and publishing metadata.
- [tcli 0.2.4 environment provider](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Configuration/EnvironmentConfig.cs): Windows User-scope precedence.
- [tcli 0.2.4 command entry point](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Program.cs): parser results, including version/help output, return exit code 1.
- [Thunderstore service-account authentication](https://github.com/thunderstore-io/Thunderstore/blob/master/django/thunderstore/account/authentication.py), [default authentication settings](https://github.com/thunderstore-io/Thunderstore/blob/master/django/thunderstore/core/settings.py), and [current-user API](https://github.com/thunderstore-io/Thunderstore/blob/master/django/thunderstore/social/api/experimental/views/current_user.py): Bearer-token authentication and the authenticated profile's `teams` array.
- [Thunderstore upload form](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/package_upload.py) and [listing update behavior](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/models/package.py): empty submitted categories retain existing listing categories.
- [Thunderstore manifest serializer](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/package_manifest.py): standard manifest fields and duplicate-version validation.
+76 -22
View File
@@ -75,12 +75,15 @@ function New-PublishFixture {
[IO.File]::WriteAllText((Join-Path $script:fixtureDir 'CHANGELOG.md'), '<details><summary>English</summary>' + "`n* 1.2.3`n</details><details><summary>Second language</summary>`n* 1.2.3`n</details>")
$script:calls = New-Object 'System.Collections.Generic.List[string]'
$script:requests = New-Object 'System.Collections.Generic.List[string]'
$script:profileRequests = New-Object 'System.Collections.Generic.List[string]'
$script:layout = $false
$script:failStep = ''
$script:tcliVersionOutput = 'tcli 0.2.4+synthetic'
$script:badArchive = ''
$script:remoteState = 'available'
$script:expectedNamespace = 'AnotherTeam'
$script:profileState = 'available'
$script:profileResponse = [pscustomobject]@{ username = 'synthetic-service-account'; teams = @($script:expectedNamespace) }
$script:published = $false
$script:capturedConfig = $null
$script:capturedConfigPath = $null
@@ -163,7 +166,7 @@ function Invoke-PublishDotNet {
Assert-Check (-not ($Arguments -contains '--token')) 'A token was put in the command line.'
$script:capturedConfigPath = $Arguments[[Array]::IndexOf($Arguments, '--config-path') + 1]
$script:capturedConfig = [IO.File]::ReadAllText($script:capturedConfigPath)
Assert-Check ($script:capturedConfig -match ('namespace = "' + $script:expectedNamespace + '"')) 'The supplied namespace was not used.'
Assert-Check ($script:capturedConfig.Contains('namespace = "' + $script:expectedNamespace + '"')) 'The namespace returned by the token lookup was not preserved.'
Assert-Check ($script:capturedConfig -match 'name = "ManifestPackage"') 'Package Name was not read from the manifest.'
Assert-Check ($script:capturedConfig -match 'communities = \["dyson-sphere-program"\]' -and $script:capturedConfig -match 'categories = \[\]') 'Community/categories are incorrect.'
Assert-Check (-not $script:capturedConfig.Contains($script:syntheticToken)) 'A token was written to TOML.'
@@ -174,7 +177,16 @@ function Invoke-PublishDotNet {
}
function Invoke-RestMethod {
param([string]$Uri, [string]$Method, [int]$TimeoutSec, [string]$ErrorAction)
param([string]$Uri, [string]$Method, [int]$TimeoutSec, [string]$ErrorAction, [hashtable]$Headers, [int]$MaximumRedirection)
if ($Uri -eq 'https://thunderstore.io/api/experimental/current-user/') {
$script:profileRequests.Add($Uri)
Assert-Check ($Headers.Authorization -ceq "Bearer $script:syntheticToken") 'The Team lookup did not use the selected token as a Bearer credential.'
Assert-Check ($Method -eq 'Get' -and $TimeoutSec -eq 30 -and $PSBoundParameters.ContainsKey('MaximumRedirection') -and $MaximumRedirection -eq 0) 'The Team lookup could redirect credentials or lacked its request timeout.'
if ($script:profileState -match '^http ([0-9]+)$') { throw [PublishCheckHttpException]::new([int]$Matches[1]) }
if ($script:profileState -eq 'offline') { throw "Synthetic transport exception containing $script:syntheticToken" }
return $script:profileResponse
}
Assert-Check ($null -eq $Headers) 'Credentials were forwarded to the public version endpoint.'
$script:requests.Add($Uri)
if ($script:remoteState -eq 'available') { throw [PublishCheckHttpException]::new(404) }
if ($script:remoteState -eq 'server error') { throw [PublishCheckHttpException]::new(503) }
@@ -185,6 +197,7 @@ function Invoke-RestMethod {
try {
New-PublishFixture
Assert-Check ('Namespace' -notin @($ast.ParamBlock.Parameters | ForEach-Object { $_.Name.VariablePath.UserPath })) 'The public script still accepts -Namespace.'
$externalTokenFile = Join-Path $sandbox 'synthetic.env'
[IO.File]::WriteAllText($externalTokenFile, "# Synthetic credentials only`nTCLI_AUTH_TOKEN='$script:syntheticToken'`n")
[Environment]::SetEnvironmentVariable('TCLI_AUTH_TOKEN', $script:callerToken, 'Process')
@@ -215,40 +228,81 @@ try {
Assert-CheckThrows { Get-PublishToken } '*Set a non-empty*'
} finally { Pop-Location }
Invoke-ModPublish -RepositoryRoot $script:fixtureRoot -Project Fixture -Namespace AnotherTeam -DryRun -EnvFile 'does-not-exist' 6>$null
Assert-Check (-not $script:published -and $script:requests.Count -eq 0) 'DryRun attempted publication or remote checks.'
[Environment]::SetEnvironmentVariable('TCLI_AUTH_TOKEN', [NullString]::Value, 'Process')
$script:profileState = 'offline'
$dryOutput = @(Invoke-ModPublish -RepositoryRoot $script:fixtureRoot -Project Fixture -DryRun -EnvFile 'does-not-exist' 6>&1)
Assert-Check (-not $script:published -and $script:requests.Count -eq 0 -and $script:profileRequests.Count -eq 0) 'DryRun attempted publication or remote checks.'
Assert-Check (@($script:calls | Where-Object { $_ -like 'tool|*' }).Count -eq 0) 'DryRun required tcli.'
foreach ($invalidNamespace in @('', 'Bad Team', "Team`n")) {
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture $invalidNamespace -DryRun } '*-Namespace*'
}
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot '..\Fixture' AnotherTeam -DryRun } '*-Project*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot FixturePreloader AnotherTeam -DryRun } '*main mod*'
Assert-Check (($dryOutput -join "`n").Contains('not queried (resolved from token when publishing)')) 'DryRun claimed to know the Team without querying it.'
Assert-Check (-not [IO.Directory]::Exists((Join-Path $script:fixtureDir 'obj\thunderstore-publish'))) 'DryRun generated publishing configuration without a resolved Team.'
Assert-Check ([IO.File]::Exists($script:fixtureZip)) 'DryRun did not retain the prepared ZIP.'
[Environment]::SetEnvironmentVariable('TCLI_AUTH_TOKEN', $script:callerToken, 'Process')
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot '..\Fixture' -DryRun } '*-Project*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot FixturePreloader -DryRun } '*main mod*'
New-PublishFixture
$script:layout = $true
$null = [IO.Directory]::CreateDirectory((Join-Path $script:fixturePackage 'patchers'))
[IO.File]::WriteAllText((Join-Path $script:fixturePackage 'patchers\FixturePreloader.dll'), 'stale preloader')
Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam -DryRun 6>$null
Invoke-ModPublish $script:fixtureRoot Fixture -DryRun 6>$null
Assert-Check (($script:calls | Where-Object { $_ -like 'build|*' } | Select-Object -First 1) -like '*CopyToParentPackage*') 'The preloader was not copied before the main mod was packaged.'
Assert-Check ([IO.File]::ReadAllText((Join-Path $script:fixturePackage 'patchers\FixturePreloader.dll')) -ceq 'fresh preloader') 'A stale preloader was packaged.'
foreach ($badZip in @('unsafe', 'duplicate', 'credential', 'missing DLL', 'stale DLL', 'wrong version')) {
New-PublishFixture
$script:badArchive = $badZip
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam -DryRun } '*ZIP*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture -DryRun } '*ZIP*'
Assert-Check (-not $script:published) 'An invalid ZIP was published.'
}
New-PublishFixture
[IO.File]::WriteAllText((Join-Path $script:fixtureDir 'CHANGELOG.md'), "<details>`n* 1.2.3`n</details><details>`n* 1.2.2`n</details>")
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam -DryRun } '*every language*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture -DryRun } '*every language*'
New-PublishFixture
$smallIcon = New-Object Drawing.Bitmap(128, 128)
try { $smallIcon.Save((Join-Path $script:fixturePackage 'icon.png'), [Drawing.Imaging.ImageFormat]::Png) } finally { $smallIcon.Dispose() }
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam -DryRun } '*256x256 PNG*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture -DryRun } '*256x256 PNG*'
$badProfiles = @(
@{ Response = $null; Pattern = '*unauthenticated or malformed*' },
@{ Response = [pscustomobject]@{ teams = @('AnotherTeam') }; Pattern = '*unauthenticated or malformed*' },
@{ Response = [pscustomobject]@{ username = $null; teams = @('AnotherTeam') }; Pattern = '*unauthenticated or malformed*' },
@{ Response = [pscustomobject]@{ username = 'synthetic' }; Pattern = '*unauthenticated or malformed*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = $null }; Pattern = '*unauthenticated or malformed*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = 'AnotherTeam' }; Pattern = '*unauthenticated or malformed*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = @() }; Pattern = '*no active Team*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = @('One', 'Two') }; Pattern = '*multiple Teams*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = @('One', 'One') }; Pattern = '*multiple Teams*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = @(123) }; Pattern = '*invalid Team name*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = @('') }; Pattern = '*invalid Team name*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = @('Bad Team') }; Pattern = '*invalid Team name*' },
@{ Response = [pscustomobject]@{ username = 'synthetic'; teams = @("Team`n") }; Pattern = '*invalid Team name*' }
)
foreach ($badProfile in $badProfiles) {
New-PublishFixture
$script:profileResponse = $badProfile.Response
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile } $badProfile.Pattern
Assert-Check (-not $script:published -and $script:requests.Count -eq 0 -and $script:profileRequests.Count -eq 1 -and $script:calls.Count -eq 1) 'An ambiguous or invalid Team fell through to the build or publication.'
Assert-Check ((Get-Location).Path -ceq $savedLocation -and [Environment]::GetEnvironmentVariable('TCLI_AUTH_TOKEN', 'Process') -ceq $script:callerToken) 'A Team lookup failure changed the caller directory or token.'
}
foreach ($profileFailure in @('http 401', 'http 403', 'http 302', 'http 429', 'http 503', 'offline')) {
New-PublishFixture
$script:profileState = $profileFailure
$failureMessage = ''
try { Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile 6>$null } catch { $failureMessage = $_.Exception.Message }
Assert-Check ($failureMessage -like '*Cannot query*Team*' -and -not $failureMessage.Contains($script:syntheticToken)) 'A failed Team lookup was ignored or exposed credentials.'
Assert-Check (-not $script:published -and $script:requests.Count -eq 0 -and $script:calls.Count -eq 1 -and $script:profileRequests.Count -eq 1) 'A failed Team lookup fell through to the build or publication.'
}
New-PublishFixture
$script:expectedNamespace = 'Mixed_CASE_42'
$script:profileResponse.teams = @($script:expectedNamespace)
$publishOutput = @(Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile 6>&1)
Assert-Check (($publishOutput -join "`n").Contains('/Mixed_CASE_42/ManifestPackage/')) 'The published package link did not use the resolved Team.'
Assert-Check ($script:requests[0] -like '*/Mixed_CASE_42/ManifestPackage/1.2.3/') 'The version lookup did not use the resolved Team.'
Assert-Check (-not ($publishOutput -join "`n").Contains($script:syntheticToken)) 'Publication logs exposed the token.'
New-PublishFixture
$script:tcliVersionOutput = 'Synthetic tool startup error without a version'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam $externalTokenFile } '*recognizable tcli version*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile } '*recognizable tcli version*'
Assert-Check (-not $script:published -and $script:requests.Count -eq 0 -and $script:calls.Count -eq 1) 'An invalid tool version fell through to the build or publication.'
foreach ($failure in @('tool', 'evaluate', 'restore', 'preloader', 'build')) {
@@ -258,22 +312,22 @@ try {
if ($failure -eq 'preloader') { $script:layout = $true }
# Leave an older ZIP to ensure a failed build never publishes it.
[IO.File]::WriteAllText($script:fixtureZip, 'old zip')
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam $externalTokenFile } '*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile } '*'
Assert-Check (-not $script:published -and $script:requests.Count -eq 0) 'A build failure fell through to publication.'
}
foreach ($remote in @('existing', 'server error', 'offline', 'malformed')) {
New-PublishFixture
$script:remoteState = $remote
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam $externalTokenFile } '*'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile } '*'
Assert-Check (-not $script:published) 'An existing/unverifiable version was published.'
Assert-Check ($script:requests[0] -like '*/AnotherTeam/ManifestPackage/1.2.3/') 'The version lookup did not use the selected Team and manifest name.'
Assert-Check ($script:requests[0] -like '*/AnotherTeam/ManifestPackage/1.2.3/') 'The version lookup did not use the resolved Team and manifest name.'
}
foreach ($failure in @('', 'publish')) {
New-PublishFixture
$script:failStep = $failure
if ($failure) { Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam $externalTokenFile } '*Inspect https://*before retrying*' }
else { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam $externalTokenFile 6>$null }
if ($failure) { Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile } '*Inspect https://*before retrying*' }
else { Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile 6>$null }
Assert-Check ([Environment]::GetEnvironmentVariable('TCLI_AUTH_TOKEN', 'Process') -ceq $script:callerToken) 'The process token was not restored.'
Assert-Check ((Get-Location).Path -ceq $savedLocation) 'The caller directory was not restored.'
Assert-Check (-not [IO.Directory]::Exists([IO.Path]::GetDirectoryName($script:capturedConfigPath))) 'Generated configuration was not cleaned up.'
@@ -284,18 +338,18 @@ try {
New-PublishFixture
Push-Location -LiteralPath $sandbox
try {
Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam 'synthetic.env' 6>$null
Invoke-ModPublish $script:fixtureRoot Fixture 'synthetic.env' 6>$null
Assert-Check ((Get-Location).Path -ceq $sandbox) 'The external caller directory was not restored.'
[IO.File]::WriteAllText((Join-Path $sandbox '.env'), "TCLI_AUTH_TOKEN=$script:syntheticToken")
[IO.File]::WriteAllText((Join-Path $script:fixtureRoot '.env'), 'TCLI_AUTH_TOKEN=synthetic-wrong-repository-token')
$script:published = $false
Invoke-ModPublish -RepositoryRoot $script:fixtureRoot -Project Fixture -Namespace AnotherTeam 6>$null
Invoke-ModPublish -RepositoryRoot $script:fixtureRoot -Project Fixture 6>$null
Assert-Check $script:published 'Publication did not use .env from the caller directory.'
Assert-Check ((Get-Location).Path -ceq $sandbox) 'Default .env lookup did not restore the caller directory.'
} finally { Pop-Location }
[Environment]::SetEnvironmentVariable('TCLI_AUTH_TOKEN', [NullString]::Value, 'Process')
New-PublishFixture
Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam $externalTokenFile 6>$null
Invoke-ModPublish $script:fixtureRoot Fixture $externalTokenFile 6>$null
Assert-Check ($null -eq [Environment]::GetEnvironmentVariable('TCLI_AUTH_TOKEN', 'Process')) 'An originally absent process token was not removed.'
# Use real MSBuild output: string stubs cannot reproduce native decoding bugs.