fix(web): measure function source size without Buffer
ci / check (push) Successful in 1m12s
ci / publish (push) Successful in 45s

Creating a function in the browser failed with 'Buffer is not defined':
the zod schema in domain/workflow-function.ts is bundled into the web app.
TextEncoder works in both. A lint rule now rejects Buffer/process in
domain and web, since Vitest runs in Node and cannot catch this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
homelab-updaterandClaude Opus 5 committed 2026-09-22 18:18:26 +02:00
1 parent 6e17ac78eb
commit cfbf5038c1
2 files changed
+12 -1

No files matched your search

+11
View File
@@ -18,5 +18,16 @@ export default tseslint.config(
},
},
...layerRules,
// domain is bundled into the browser with web: Node-only globals break there at runtime, not in Vitest (Node).
{
files: ['src/domain/**/*.ts', 'src/web/**/*.{ts,tsx}'],
ignores: ['**/*.test.{ts,tsx}'],
rules: {
'no-restricted-globals': ['error',
{ name: 'Buffer', message: 'Not in the browser: use TextEncoder/TextDecoder.' },
{ name: 'process', message: 'Not in the browser.' },
],
},
},
{ files: ['*.config.js'], ...tseslint.configs.disableTypeChecked },
);
+1 -1
View File
@@ -43,7 +43,7 @@ export type FunctionTestCase = z.infer<typeof FunctionTestCase>;
export const WorkflowFunctionDocumentV1 = z.object({
schemaVersion: z.literal(1),
language: z.enum(['typescript', 'posix']),
source: z.string().min(1).refine((value) => !value.includes('\0'), 'source cannot contain NUL').refine((value) => Buffer.byteLength(value, 'utf8') <= FUNCTION_MAX_SOURCE_BYTES, 'source is too large'),
source: z.string().min(1).refine((value) => !value.includes('\0'), 'source cannot contain NUL').refine((value) => new TextEncoder().encode(value).length <= FUNCTION_MAX_SOURCE_BYTES, 'source is too large'),
capabilities: FunctionCapabilitySetV1,
cases: z.array(FunctionTestCase).min(1).max(FUNCTION_MAX_CASES),
}).strict().superRefine((document, context) => {