Skip to content

broker: accept org IDs in deprecated workspace alias schema#200

Merged
benvinegar merged 2 commits intomainfrom
fix/broker-orgid-schema-validation
Mar 6, 2026
Merged

broker: accept org IDs in deprecated workspace alias schema#200
benvinegar merged 2 commits intomainfrom
fix/broker-orgid-schema-validation

Conversation

@benvinegar
Copy link
Member

Summary

  • fix env schema mismatch causing baudbot broker register --org-id ... to fail validation
  • allow deprecated workspace alias vars to accept org IDs as plain strings
  • add regression coverage in bin/broker-register.test.mjs so schema cannot regress to startsWith=T

Root cause

broker register intentionally mirrors org ID into SLACK_BROKER_WORKSPACE_ID for backward compatibility. The schema still enforced startsWith=T on that deprecated key, causing false config failures.

Verification

  • node --test bin/broker-register.test.mjs
  • npm run lint
  • DigitalOcean Arch droplet end-to-end check:
    • sudo baudbot broker register --org-id org_...
    • varlock load --path ~/.config/ passes after registration

@greptile-apps
Copy link

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR fixes a schema validation mismatch that caused baudbot broker register --org-id ... to fail: the two deprecated backward-compatibility keys (GATEWAY_BROKER_WORKSPACE_ID, SLACK_BROKER_WORKSPACE_ID) previously enforced a startsWith=T constraint, which rejected modern org_...-format org IDs that the registration flow mirrors into those fields. The fix is a one-line annotation change per key in .env.schema, paired with a new regression test that reads the schema file directly and asserts the correct @type=string annotation is present on both keys.

Key changes:

  • .env.schema: Drops startsWith=T from GATEWAY_BROKER_WORKSPACE_ID and SLACK_BROKER_WORKSPACE_ID; adds a clarifying comment explaining both value formats are now accepted.
  • bin/broker-register.test.mjs: New test parses .env.schema at runtime to guard against future regressions back to the constrained annotation.

Minor concern:

  • The test resolves .env.schema via path.resolve(".env.schema"), which is CWD-dependent. Running the test from any directory other than the project root would produce an ENOENT error. Anchoring with new URL("../.env.schema", import.meta.url) would be more robust.

Confidence Score: 5/5

  • Safe to merge — minimal targeted schema fix with direct regression test coverage.
  • The change is extremely small (two annotation edits, one new test), directly addresses the documented root cause, and does not touch any business logic or security-sensitive code. The only flag is a minor CWD fragility in the new test that does not affect correctness under the documented invocation.
  • No files require special attention.

Important Files Changed

Filename Overview
.env.schema Removes the startsWith=T constraint from GATEWAY_BROKER_WORKSPACE_ID and SLACK_BROKER_WORKSPACE_ID, allowing org IDs (org_...) alongside legacy Slack workspace IDs; adds an explanatory comment. Change is correct and intentional.
bin/broker-register.test.mjs Adds a regression test that reads .env.schema directly and asserts both deprecated workspace-ID keys carry a plain @type=string annotation. The CWD-relative path.resolve(".env.schema") is mildly fragile but functional when run from the project root as documented.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["baudbot broker register --org-id org_..."] --> B["runRegistration()"]
    B --> C["mirrors org_id into SLACK_BROKER_WORKSPACE_ID"]
    C --> D{"varlock load validates .env.schema"}
    D -- "BEFORE (startsWith=T)" --> E["❌ Validation failure\norg_... does not start with T"]
    D -- "AFTER (@type=string)" --> F["✅ Validation passes\nboth T... and org_... accepted"]
Loading

Last reviewed commit: adf3c3a

});

test("env schema accepts org IDs for deprecated workspace aliases", () => {
const schemaPath = path.resolve(".env.schema");
Copy link

Choose a reason for hiding this comment

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

CWD-relative path resolution is fragile

path.resolve(".env.schema") resolves relative to the process's current working directory at the time the test runs. If the test is ever invoked from a directory other than the project root (e.g. cd bin && node --test broker-register.test.mjs), the resolved path will be wrong and the test will throw ENOENT rather than giving a useful assertion failure.

Using import.meta.url gives an anchor that is always relative to this source file, regardless of CWD:

Suggested change
const schemaPath = path.resolve(".env.schema");
const schemaPath = new URL("../.env.schema", import.meta.url).pathname;
Prompt To Fix With AI
This is a comment left during a code review.
Path: bin/broker-register.test.mjs
Line: 270

Comment:
**CWD-relative path resolution is fragile**

`path.resolve(".env.schema")` resolves relative to the process's current working directory at the time the test runs. If the test is ever invoked from a directory other than the project root (e.g. `cd bin && node --test broker-register.test.mjs`), the resolved path will be wrong and the test will throw `ENOENT` rather than giving a useful assertion failure.

Using `import.meta.url` gives an anchor that is always relative to this source file, regardless of CWD:

```suggestion
  const schemaPath = new URL("../.env.schema", import.meta.url).pathname;
```

How can I resolve this? If you propose a fix, please make it concise.

@benvinegar benvinegar merged commit 99a41ad into main Mar 6, 2026
9 checks passed
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.

1 participant