Skip to content

fix(tools): reject conflicting container config#1214

Merged
Dhravya merged 1 commit into
supermemoryai:mainfrom
GautamSharma99:fix/tools-exclusive-container-config
Jul 11, 2026
Merged

fix(tools): reject conflicting container config#1214
Dhravya merged 1 commit into
supermemoryai:mainfrom
GautamSharma99:fix/tools-exclusive-container-config

Conversation

@GautamSharma99

@GautamSharma99 GautamSharma99 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds runtime validation for @supermemory/tools container scoping configuration.

SupermemoryToolsConfig already documents projectId and containerTags as mutually exclusive,
but the implementation did not enforce that. When both were provided, getContainerTags()
silently preferred projectId and ignored containerTags.

Problem

Before this change:

supermemoryTools(apiKey, {
projectId: "abc",
containerTags: ["user_123"],
})

silently resolved to:

["sm_project_abc"]

The explicit containerTags value was ignored, which could cause memory/search operations to
run against an unexpected scope.

Changes

  • Add a runtime guard in getContainerTags()
  • Throw a clear error when both projectId and containerTags are provided
  • Add focused tests for:
    • default container tag behavior
    • projectId conversion to sm_project_${id}
    • explicit containerTags
    • conflicting projectId + containerTags

Why This Matters

This makes runtime behavior match the public config contract and prevents accidental use of
the wrong memory container.

Files Changed

  • packages/tools/src/tools-shared.ts
  • packages/tools/src/tools-shared.test.ts

Testing

Passed:

bun run --cwd packages/tools test src/tools-shared.test.ts
bunx biome check packages/tools/src/tools-shared.ts packages/tools/src/tools-shared.test.ts

Also ran:

bun run --cwd packages/tools check-types

That command currently fails on existing unrelated package-wide TypeScript errors outside this
change.


Session Details

  • Session: View Session
  • Requested by: Unknown
  • Address comments on this PR. Add (aside) to your comment to have me ignore it.

@vorflux

vorflux Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Reviewed the changes in packages/tools/src/tools-shared.ts and packages/tools/src/tools-shared.test.ts, which add validation to reject conflicting projectId and containerTags configuration and cover the expected helper behavior.

Verdict

Reviewed — no issues found. The diff is narrowly scoped, the conflict check is placed before tag selection, and the added tests cover the relevant behavior.

@vorflux

vorflux Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Testing

Targeted tooling validation was performed for the changed packages/tools helper. The focused unit test, changed-path TypeScript check, and diff whitespace check all passed; package-wide type checking still has unrelated pre-existing failures on main.

Commands run:

cd packages/tools && export PATH="$HOME/.bun/bin:$PATH"; bun run test src/tools-shared.test.ts
cd packages/tools && export PATH="$HOME/.bun/bin:$PATH"; bunx tsc --noEmit --module ESNext --moduleResolution bundler --target ES2022 --strict --skipLibCheck --types vitest src/tools-shared.test.ts
git diff --check origin/main..HEAD -- packages/tools/src/tools-shared.ts packages/tools/src/tools-shared.test.ts

Result:

Targeted Vitest: PASSED — 1 test file passed, 4 tests passed.
Focused changed-path TypeScript check: PASSED.
Diff whitespace check: PASSED.

Package-wide `cd packages/tools && bun run check-types` fails on both this PR and `origin/main` with existing unrelated errors in files such as `src/ai-sdk.ts`, `src/openai/tools.ts`, `src/shared/cache.ts`, and test/example directories, so it was not treated as a PR regression.

Verdict

Passed. The changed helper behavior is covered by targeted tests and focused validation passed.

Comment on lines +66 to +70
if (config?.projectId !== undefined && config.containerTags !== undefined) {
throw new Error(
"Supermemory tools config accepts either projectId or containerTags, not both.",
)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The validation check is inconsistent with the actual usage logic below. The validation uses !== undefined while line 71 uses truthy checking (if (config?.projectId)). This means edge cases like projectId: "" or projectId: null will trigger the "both provided" error even though they are falsy and would be ignored by the actual logic.

For example:

getContainerTags({ projectId: "", containerTags: ["tag"] })

Will throw an error claiming both are provided, even though the empty string would be treated as "not provided" by line 71's truthy check.

Fix by aligning the validation with the actual usage:

if (config?.projectId && config?.containerTags) {
    throw new Error(
        "Supermemory tools config accepts either projectId or containerTags, not both.",
    )
}
Suggested change
if (config?.projectId !== undefined && config.containerTags !== undefined) {
throw new Error(
"Supermemory tools config accepts either projectId or containerTags, not both.",
)
}
if (config?.projectId && config?.containerTags) {
throw new Error(
"Supermemory tools config accepts either projectId or containerTags, not both.",
)
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

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.

2 participants