broker: accept org IDs in deprecated workspace alias schema#200
broker: accept org IDs in deprecated workspace alias schema#200benvinegar merged 2 commits intomainfrom
Conversation
Greptile SummaryThis PR fixes a schema validation mismatch that caused Key changes:
Minor concern:
Confidence Score: 5/5
Important Files Changed
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"]
Last reviewed commit: adf3c3a |
bin/broker-register.test.mjs
Outdated
| }); | ||
|
|
||
| test("env schema accepts org IDs for deprecated workspace aliases", () => { | ||
| const schemaPath = path.resolve(".env.schema"); |
There was a problem hiding this 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:
| 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.
Summary
baudbot broker register --org-id ...to fail validationbin/broker-register.test.mjsso schema cannot regress tostartsWith=TRoot cause
broker registerintentionally mirrors org ID intoSLACK_BROKER_WORKSPACE_IDfor backward compatibility. The schema still enforcedstartsWith=Ton that deprecated key, causing false config failures.Verification
node --test bin/broker-register.test.mjsnpm run lintsudo baudbot broker register --org-id org_...varlock load --path ~/.config/passes after registration