docs: add validate-conditions.ts script#784
Conversation
Adds packages/taco/scripts/validate-conditions.ts: a CLI helper that parses a conditions.json file through the SDK's ConditionExpression and reports whether it satisfies the Zod schemas. Intended for the "Validating Conditions" docs page, which previously linked to a copy hosted in an unrelated repo. Hosting the script here lets the docs reference canonical infrastructure that ships alongside the schemas it validates. Behaviour: - Optional CLI arg for the conditions file path; defaults to ./conditions.json. - Exits 1 on invalid input. - Writes the full Zod error to <input>.error.txt so it can be pasted into an LLM prompt for diagnosis.
✅ Deploy Preview for taco-nft-demo canceled.
|
✅ Deploy Preview for taco-demo canceled.
|
The "Source" section of the Validating Conditions page previously linked to a copy of validate-conditions.ts hosted in an unrelated repo, with a note that the link would move once the script was promoted into nucypher/taco-web. Replace the placeholder link and accompanying caveat with the canonical URL at nucypher/taco-web/packages/taco/scripts/. The script is added in nucypher/taco-web#784.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #784 +/- ##
===========================================
+ Coverage 23.12% 87.03% +63.90%
===========================================
Files 62 83 +21
Lines 10175 5806 -4369
Branches 260 201 -59
===========================================
+ Hits 2353 5053 +2700
+ Misses 7763 750 -7013
+ Partials 59 3 -56 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a TACo SDK-local CLI helper for validating a conditions.json file by parsing it through ConditionExpression.fromObj and reporting success/failure (including writing validation errors to a sidecar file).
Changes:
- Add
packages/taco/scripts/validate-conditions.tsCLI script to load and validate a conditions JSON file. - On validation failure, write error details to
<input>.error.txtand exit non-zero.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,45 @@ | |||
| #!/usr/bin/env npx tsx | |||
There was a problem hiding this comment.
The hashbang #!/usr/bin/env npx tsx is not a valid/portable shebang: most kernels pass everything after /usr/bin/env as a single argument, so env will look for an executable literally named "npx tsx" and the script won’t be runnable when invoked directly. Consider either removing the shebang (since the documented invocation is via pnpm tsx ...) or switching to a portable form like using env -S to split arguments (and ensuring the repo’s supported platforms include it).
| #!/usr/bin/env npx tsx |
| const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8'); | ||
| const conditionsObj = JSON.parse(conditionsJson); | ||
|
|
||
| console.log('\nConditions loaded:'); | ||
| console.log(JSON.stringify(conditionsObj, null, 2)); | ||
|
|
||
| console.log('\n--- Validating with TACo SDK ---\n'); | ||
|
|
||
| try { |
There was a problem hiding this comment.
Errors from readFileSync/JSON.parse (missing file, invalid JSON) occur before the try/catch, and the final main().catch(console.error) will log them but still exit with status 0. This contradicts the documented behavior of exiting 1 on invalid input. Wrap the file read/parse in the same try/catch (or set process.exitCode = 1 in the top-level catch) so any failure results in a non-zero exit status.
| const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8'); | |
| const conditionsObj = JSON.parse(conditionsJson); | |
| console.log('\nConditions loaded:'); | |
| console.log(JSON.stringify(conditionsObj, null, 2)); | |
| console.log('\n--- Validating with TACo SDK ---\n'); | |
| try { | |
| try { | |
| const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8'); | |
| const conditionsObj = JSON.parse(conditionsJson); | |
| console.log('\nConditions loaded:'); | |
| console.log(JSON.stringify(conditionsObj, null, 2)); | |
| console.log('\n--- Validating with TACo SDK ---\n'); |
| console.log('\nConditions loaded:'); | ||
| console.log(JSON.stringify(conditionsObj, null, 2)); | ||
|
|
There was a problem hiding this comment.
The PR description/test plan says the script prints the parsed conditionType on success, but the script currently always prints the full loaded conditions JSON (and additional status lines). If the docs are going to reference this as a canonical helper, consider minimizing default stdout to just the conditionType (and/or gating the full JSON dump behind a --verbose flag) so the output matches the documented behavior and is easier to script against.
| } | ||
| } | ||
|
|
||
| main().catch(console.error); |
There was a problem hiding this comment.
If main() rejects, main().catch(console.error) logs the error but does not set a failing exit code, so CI/consumers will see a successful exit even though validation didn’t run. Set process.exitCode = 1 (or call process.exit(1)) in this catch handler after logging.
| main().catch(console.error); | |
| main().catch((error) => { | |
| console.error(error); | |
| process.exitCode = 1; | |
| }); |
| try { | ||
| const expr = ConditionExpression.fromObj(conditionsObj); | ||
| console.log('✅ Conditions are VALID according to TACo SDK!'); | ||
| console.log('\nParsed condition type:', expr.condition.conditionType); |
There was a problem hiding this comment.
| console.log('\nParsed condition type:', expr.condition.conditionType); | |
| console.log('\nParsed condition type:', expr.condition.value.conditionType); |
Summary
Adds
packages/taco/scripts/validate-conditions.ts: a CLI helper that runs aconditions.jsonfile throughConditionExpression.fromObjand reports whether it satisfies the SDK's Zod schemas.Hosting the script alongside the schemas it validates lets the TACo docs "Validating Conditions" page link to canonical infrastructure instead of an unrelated repo.
Context
Requested in @derekpierre's review on nucypher/taco-docs#12: "If the script is tested and works well, you can add it to the
nucypher/taco-webrepos. Once this URL is fixed, I can approve."The script was previously hosted at
theref/discord-taco-web/scripts/validate-conditions.ts.Behaviour
./conditions.json.conditionTypeon success.<input>.error.txt(intended for pasting into an LLM prompt for diagnosis).Follow-up
Once this lands,
validating-conditions.mdinnucypher/taco-docswill be updated to point at the canonical script in this repo.Test plan
pnpm tsx packages/taco/scripts/validate-conditions.ts <valid.json>→ prints the parsed condition type, exits 0.pnpm tsx packages/taco/scripts/validate-conditions.ts <invalid.json>→ prints the Zod error, writes<invalid.json>.error.txt, exits 1.