fix(sdk): reject "." ".." and NUL plugin names like the python twin (#4771)

## Description

`assertPluginName` in `sdk/typescript/src/paths.ts` (line 250 on
`200c838c`) rejected only an empty name, `/` and `\`.
`pluginConfigDir(".")` returned a path ending in `plugins/.`,
`pluginConfigDir("..")` one ending in `plugins/..` (which resolves to
the config directory), `pluginWorkspaceDir("..")` the same under the
workspace root, and a name containing NUL was accepted. The Python twin,
`headroom/paths.py` (`_validate_plugin_name`), already rejects `"."`,
`".."` and NUL; its docstring explains the guard keeps one plugin away
from the others' state.

This PR applies the same rule in TypeScript. It changes nothing else.

Closes #4768

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- `sdk/typescript/src/paths.ts`: `assertPluginName` also throws for
`"."`, `".."` and a name containing `"\0"`, with a comment pointing at
the Python twin.
- `sdk/typescript/test/paths.test.ts`: the existing `rejects invalid
plugin name` cases now include `"."`, `".."` and `"a\0b"`.

## Testing

- [ ] Unit tests pass (`pytest`)
- [ ] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

This is a TypeScript-only change, so the Python checks above do not
apply; the SDK equivalents were run (Node v24.22.2, vitest 5.1.0, `npm
ci --ignore-scripts` from the committed lockfile, Ubuntu on WSL2).

### Test Output

Fail before (`paths.ts` from `200c838c`, new test cases kept):

```text
vitest run test/paths.test.ts -t "rejects invalid plugin name"
 × rejects invalid plugin name "."
 × rejects invalid plugin name ".."
 × rejects invalid plugin name "a\u0000b"
AssertionError: expected [Function] to throw an error
Tests  3 failed | 3 passed | 57 skipped (63)
```

Pass after (this branch):

```text
vitest run test/paths.test.ts -t "rejects invalid plugin name"
Tests  6 passed | 57 skipped (63)

vitest run (whole sdk/typescript suite)
Test Files  19 passed | 5 skipped (24)
Tests  462 passed | 33 skipped (495)

tsc --noEmit -> exit 0
```

## Real Behavior Proof

- Environment: Ubuntu on WSL2, Node v24.22.2, `HOME` default, the built
package (`npm ci --ignore-scripts && npx tsup` in `sdk/typescript`), not
vitest.
- Exact command / steps: `git checkout <branch>` (or `origin/main` for
"before"); `cd sdk/typescript && npm ci --ignore-scripts && npx tsup`; a
small ESM script imports `pluginConfigDir` and `pluginWorkspaceDir` from
`dist/index.js` and prints the result, or the thrown message, for
`"realplugin"`, `"."`, `".."` and `"a\u0000b"`.
- Observed result: before (`200c838c`): `pluginConfigDir(".")` ->
`/home/zxc59/.headroom/config/plugins/.`, `pluginConfigDir("..")` ->
`/home/zxc59/.headroom/config/plugins/..`, `pluginWorkspaceDir("..")` ->
`/home/zxc59/.headroom/plugins/..`, and the NUL name returned a path
containing it. After (this branch): all of these throw `invalid plugin
name: "."`, `".."` and `"a\u0000b"`; `"realplugin"` still returns
`/home/zxc59/.headroom/config/plugins/realplugin`.
- Not tested: a real plugin installed through the package manager,
Windows paths, and the browser build (where these helpers return an
empty string).

## Runtime Rollout Safety

- Rollout-managed feature(s): none; TypeScript SDK path helpers only.
- Minimum rollout channel: n/a
- Stable/default behavior changed: yes, narrowly. `pluginConfigDir` and
`pluginWorkspaceDir` now throw for `"."`, `".."` and a NUL name, as the
Python twin already did.
- Kill switch / disable path: n/a
- Unsafe override required: no
- Qualification impact: none
- Rollback path: revert this commit.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Additional Notes

- No documentation change: the SDK README does not describe the
plugin-name rule.

AI assistance: this change, its tests and the runs above were done with
Claude (Sonnet 5.5), operated by me (HetCreep).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
HetCreep
2026-11-11 10:00:53 -06:00
committed by GitHub
co-authored by Claude Sonnet 5.5
parent 4eb742abd8
commit 99ef4eec82
2 changed files with 11 additions and 2 deletions
+10 -1
View File
@@ -248,7 +248,16 @@ export function modelsConfigPath(): string {
// ---------------------------------------------------------------------------
function assertPluginName(name: string): void {
if (!name || name.includes("/") || name.includes("\\")) {
// Same rule as the Python twin (headroom/paths.py): "." and ".." would resolve
// to plugins/ itself or to the parent, and NUL ends a path in POSIX APIs.
if (
!name ||
name === "." ||
name === ".." ||
name.includes("/") ||
name.includes("\\") ||
name.includes("\0")
) {
throw new Error(`invalid plugin name: ${JSON.stringify(name)}`);
}
}
+1 -1
View File
@@ -390,7 +390,7 @@ describe("plugin dirs", () => {
);
});
for (const bad of ["", "foo/bar", "foo\\bar"]) {
for (const bad of ["", "foo/bar", "foo\\bar", ".", "..", "a\0b"]) {
it(`rejects invalid plugin name ${JSON.stringify(bad)}`, () => {
expect(() => pluginConfigDir(bad)).toThrow();
expect(() => pluginWorkspaceDir(bad)).toThrow();