@quantcdn/edge-conformance 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Quant edge conformance vectors and runner.
2
+ Copyright 2026 QuantCDN Pty Ltd
3
+
4
+ This product includes software developed by QuantCDN Pty Ltd.
package/README.md CHANGED
@@ -1,3 +1,106 @@
1
- # Temporary Holding Version
1
+ # @quantcdn/edge-conformance
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Conformance vectors for the Quant edge: rule matching, static serving and edge functions. Any implementation of that behaviour can run them through an adapter. Two implementations use them:
4
+
5
+ - `quant serve` (in [`@quantcdn/quant-cli`](https://www.npmjs.com/package/@quantcdn/quant-cli)), the local edge, through an in-process adapter.
6
+ - The Quant edge itself, through a runtime adapter (see [`adapters/runtime/README.md`](adapters/runtime/README.md)).
7
+
8
+ When both pass the same cases, a site behaves the same on a developer's machine and in production.
9
+
10
+ The vectors hold documented behaviour only: the [Quant documentation](https://docs.quantcdn.io) for page rules, auth middleware, content filters and edge functions, and the code-managed rules manifest (`quant/edge-rules.json`). KV and ledger behaviour is in a separate suite, [`@quantcdn/kv-ledger-conformance`](https://github.com/quantcdn/kv-ledger-conformance).
11
+
12
+ ## Run the suite
13
+
14
+ Node.js 20 or later. The package has no dependencies.
15
+
16
+ ```sh
17
+ npm install --save-dev @quantcdn/edge-conformance
18
+ npx edge-conformance --adapter ./my-adapter.mjs
19
+ npx edge-conformance --adapter ./my-adapter.mjs --tags rules,static
20
+ npx edge-conformance --adapter ./my-adapter.mjs --json
21
+ ```
22
+
23
+ The command exits `0` when no case fails, `1` when a case fails and `2` for a usage error.
24
+
25
+ From code:
26
+
27
+ ```js
28
+ import { run } from '@quantcdn/edge-conformance';
29
+ import { createAdapter } from './my-adapter.mjs';
30
+
31
+ const result = await run({ adapter: createAdapter(), tags: ['functions'] });
32
+ // { passed, failed, skipped, cases: [{ id, op, tags, file, status, failures }] }
33
+ ```
34
+
35
+ `loadCases()`, `selectCases()` and `checkResult()` are exported too, so a test framework can give each case its own test.
36
+
37
+ ## Adapters
38
+
39
+ An adapter module exports `createAdapter()` (named or default). The adapter implements some or all of four operations and lists them in `capabilities.ops`. The runner skips the cases for an operation that the adapter does not list. The types are in [`src/adapter.d.ts`](src/adapter.d.ts).
40
+
41
+ | Operation | Arguments | Answer |
42
+ |---|---|---|
43
+ | `matchRule` | `(rules, functions, request)` | `{ ruleId }`: the id of the first enabled function or auth rule that matches, or `null` |
44
+ | `serveStatic` | `(files, request)` | `{ status, headers, bodyText }` from the static files only |
45
+ | `runFunction` | `({ uuid, type, body, request, response? })` | `{ status, headers, bodyText }` for one function on every path |
46
+ | `serveSite` | `({ files, functions, rules, request })` | `{ status, headers, bodyText }` for a whole site |
47
+
48
+ - `rules` is a manifest in the `quant/edge-rules.json` format (`version`, `namespace`, `rules`).
49
+ - `functions` is a list of `{ uuid, id, type, body }`. `type` is `function`, `auth` or `filter`, and `body` is the function source.
50
+ - `files` maps a path relative to the site root (for example `about/index.html`) to its content.
51
+ - `request` is `{ method, url, headers?, body? }`. The `url` is absolute, and its host is the request host.
52
+ - For a `filter`, `response` is the response that the filter gets: `{ status, headers, body }`.
53
+ - `headers` in an answer is an object. A header with more than one value (`set-cookie`) can be a list.
54
+
55
+ An adapter can set `capabilities.excludeTags` to skip the cases with those tags. `dispose()`, when present, runs after the last case.
56
+
57
+ ## Vectors
58
+
59
+ The cases are JSON files in `vectors/<suite>/`. Each file holds `{ "cases": [...] }`, and each case has this shape:
60
+
61
+ ```json
62
+ {
63
+ "id": "rules-wildcard-needs-a-character",
64
+ "description": "A * matches one or more characters, so /blog/* does not match /blog/.",
65
+ "tags": ["rules"],
66
+ "op": "matchRule",
67
+ "input": { "rules": { "version": 1, "namespace": "conformance", "rules": [] }, "functions": [], "request": { "method": "GET", "url": "https://www.example.com/blog/" } },
68
+ "expect": { "ruleId": null }
69
+ }
70
+ ```
71
+
72
+ A response expectation can have:
73
+
74
+ - `status`: the exact status.
75
+ - `headers`: for each header, the exact text, `null` (the header is absent), a list (the values in order), or one of `{ "present": true }`, `{ "startsWith": "..." }` and `{ "includes": "..." }`.
76
+ - `bodyText` (exact), `bodyIncludes` and `bodyExcludes` (substrings), `bodyJson` (the body is JSON that contains these values).
77
+
78
+ A case checks only what it states. The cases do not check the headers that only one implementation adds, for example the local `cache-control: no-store` on static files in `quant serve`.
79
+
80
+ ### Tags
81
+
82
+ | Tag | Meaning |
83
+ |---|---|
84
+ | `rules` | Rule matching and the request pipeline: patterns, domains, methods, weight, auth middleware |
85
+ | `static` | Static paths, index files, the `/_quant404` page, content types, HEAD and byte ranges |
86
+ | `functions` | The edge function contract: the `event` object, globals, responses, errors and content filters |
87
+ | `unverified` | The expected value comes from the documentation, and the runtime run has not checked it yet |
88
+
89
+ Each case has exactly one suite tag. The runtime adapter run checks each `unverified` case. If the case passes, the tag is removed. If the case fails, the case, the documentation or the implementation is fixed so that all three agree.
90
+
91
+ A case is never weakened only to make an implementation pass.
92
+
93
+ ### What is not in the vectors
94
+
95
+ The suite does not cover production security protections or time, memory and capacity limits. A site does not depend on them, and a local implementation does not copy them.
96
+
97
+ ## Contribute a case
98
+
99
+ 1. Find the behaviour in the public documentation, or confirm it against the production edge.
100
+ 2. Add the case to the file for its suite in `vectors/`. Use `www.example.com` for hosts and documentation addresses (for example `203.0.113.9`) for IP addresses.
101
+ 3. Add the `unverified` tag when the runtime run has not checked the expected value yet.
102
+ 4. Run `npm test`. The tests check the case shape, the tags and the case counts.
103
+
104
+ ## License
105
+
106
+ Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,46 @@
1
+ # Runtime adapter
2
+
3
+ The runtime adapter runs the vectors against the production Quant edge. It is not written yet. This file states what it must do, so that its author and its reviewer have the same contract.
4
+
5
+ The adapter follows the interface in [`src/adapter.d.ts`](../../src/adapter.d.ts) and the README. It must use only public interfaces: a Quant project made for the test, the public deploy path for files, functions and the code-managed rules manifest (`quant/edge-functions.json` and `quant/edge-rules.json`), and ordinary HTTPS requests to the project's domain. It must not use private endpoints, private headers or knowledge of how the edge is built, and it must contain no credentials. Credentials come from the environment of the person who runs it and are never printed.
6
+
7
+ ## Operations
8
+
9
+ The adapter must implement all four operations and list them in `capabilities.ops`.
10
+
11
+ ### `serveSite({ files, functions, rules, request })`
12
+
13
+ 1. Deploy `files` as the site content (each key is a path relative to the site root).
14
+ 2. Deploy `functions` with the given `uuid`, `type` and `body`, and `rules` as the code-managed rules manifest.
15
+ 3. Send `request` to the project's domain: the method, the path and query of `request.url`, the headers and the body. Do not follow redirects.
16
+ 4. Answer `{ status, headers, bodyText }`. Give `set-cookie` as a list when the response has more than one.
17
+
18
+ The request host in a vector is `www.example.com` (or another `example.com` name). The adapter maps it to the test domain. A case that matches on the domain needs that domain to be attached to the test project, or the adapter must list the case as skipped and say why.
19
+
20
+ ### `serveStatic(files, request)`
21
+
22
+ The same as `serveSite` with no functions and no rules.
23
+
24
+ ### `runFunction({ uuid, type, body, request, response })`
25
+
26
+ Deploy one function and one rule of its `type` with the URL patterns `/` and `/*`, then send the request.
27
+
28
+ - `function` and `auth`: the answer is the response to the request.
29
+ - `filter`: also deploy a function rule on `/` and `/*` whose function returns `response` (its status, headers and body). The filter rule then runs over that response.
30
+
31
+ ### `matchRule(rules, functions, request)`
32
+
33
+ Deploy each function or auth rule with a function that identifies the rule:
34
+
35
+ - A function rule answers 200 with the rule id as the body.
36
+ - An auth rule answers 401 with the rule id as the body.
37
+
38
+ Filter rules are deployed as given, with a filter that does not change the response. Send the request and answer `{ ruleId }`: the body of a 200 or 401 answer from one of these functions, or `null` when the request reached static content or the 404 page.
39
+
40
+ ## Speed and isolation
41
+
42
+ A deploy for each case is slow. The adapter can group cases that use the same files, functions and rules, and it must purge or version the content so that one case never sees the content of another case.
43
+
44
+ ## Review
45
+
46
+ The runtime owner reviews this adapter and the result of its first run. For each failed case, the result says whether the documentation, the case or the implementation is wrong. Each case tagged `unverified` that passes in production loses the tag.
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@quantcdn/edge-conformance",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Conformance vectors for Quant edge rules, static serving and edge functions, with a runner for any adapter.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.js"
8
+ },
9
+ "types": "./src/adapter.d.ts",
10
+ "bin": {
11
+ "edge-conformance": "src/cli.js"
12
+ },
13
+ "files": [
14
+ "src",
15
+ "vectors",
16
+ "adapters",
17
+ "LICENSE",
18
+ "README.md",
19
+ "NOTICE"
20
+ ],
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "test": "node --test test/*.test.mjs"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/quantcdn/edge-conformance.git"
33
+ },
34
+ "keywords": [
35
+ "quant",
36
+ "edge",
37
+ "conformance",
38
+ "test-vectors"
39
+ ],
40
+ "license": "Apache-2.0",
41
+ "homepage": "https://github.com/quantcdn/edge-conformance#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/quantcdn/edge-conformance/issues"
44
+ }
45
+ }
@@ -0,0 +1,134 @@
1
+ // Types for @quantcdn/edge-conformance: the adapter interface, the vector
2
+ // case shape and the runner.
3
+
4
+ /** A request as a vector gives it. `url` is absolute; its host is the request host. */
5
+ export interface CaseRequest {
6
+ method: string;
7
+ url: string;
8
+ headers?: Record<string, string>;
9
+ body?: string;
10
+ }
11
+
12
+ /** A rules manifest in the quant/edge-rules.json format. */
13
+ export interface RulesManifest {
14
+ version: 1;
15
+ namespace: string;
16
+ rules: Array<{
17
+ id: string;
18
+ type: 'function' | 'auth' | 'filter';
19
+ urls: string[];
20
+ domains?: string[];
21
+ methods?: string[];
22
+ weight: number;
23
+ disabled?: boolean;
24
+ function_uuid?: string;
25
+ function_ref?: string;
26
+ }>;
27
+ }
28
+
29
+ /** A function as a vector gives it. `body` is the function source (absent for matchRule). */
30
+ export interface CaseFunction {
31
+ uuid: string;
32
+ id?: string;
33
+ type: 'function' | 'auth' | 'filter';
34
+ body?: string;
35
+ }
36
+
37
+ /** The answer of every operation except matchRule. Header names are not case sensitive. */
38
+ export interface CaseResponse {
39
+ status: number;
40
+ /** One string for each header; set-cookie can be a list of strings. */
41
+ headers: Record<string, string | string[]>;
42
+ bodyText: string;
43
+ }
44
+
45
+ export interface RunFunctionInput {
46
+ uuid: string;
47
+ type: 'function' | 'auth' | 'filter';
48
+ body: string;
49
+ request: CaseRequest;
50
+ /** filter only: the response that the filter gets. */
51
+ response?: { status: number; headers?: Record<string, string>; body?: string | null };
52
+ /** Reserved for KV cases; no vector in this version uses it. */
53
+ kv?: unknown;
54
+ }
55
+
56
+ export interface ServeSiteInput {
57
+ files?: Record<string, string>;
58
+ functions?: CaseFunction[];
59
+ rules?: RulesManifest;
60
+ request: CaseRequest;
61
+ }
62
+
63
+ export interface Capabilities {
64
+ /** The operations that the adapter implements. Cases for other operations are skipped. */
65
+ ops: Array<'matchRule' | 'serveStatic' | 'runFunction' | 'serveSite'>;
66
+ /** Cases with any of these tags are skipped. */
67
+ excludeTags?: string[];
68
+ }
69
+
70
+ export interface Adapter {
71
+ capabilities: Capabilities;
72
+ /** The id of the first enabled function or auth rule that matches, or null. */
73
+ matchRule?(rules: RulesManifest, functions: CaseFunction[], request: CaseRequest): Promise<{ ruleId: string | null }>;
74
+ /** Serve the request from the static files only (path -> content, relative to the site root). */
75
+ serveStatic?(files: Record<string, string>, request: CaseRequest): Promise<CaseResponse>;
76
+ /** Run one function for the request, as a rule of its type on every path would. */
77
+ runFunction?(input: RunFunctionInput): Promise<CaseResponse>;
78
+ /** Serve the request from a whole site: files, functions and rules. */
79
+ serveSite?(input: ServeSiteInput): Promise<CaseResponse>;
80
+ dispose?(): Promise<void>;
81
+ }
82
+
83
+ /** A header matcher: exact text, null (absent), a list (in order) or one test. */
84
+ export type HeaderMatcher = string | null | string[] | { present: true } | { startsWith: string } | { includes: string };
85
+
86
+ export interface CaseExpect {
87
+ ruleId?: string | null;
88
+ status?: number;
89
+ headers?: Record<string, HeaderMatcher>;
90
+ bodyText?: string;
91
+ bodyIncludes?: string[];
92
+ bodyExcludes?: string[];
93
+ /** The body parses as JSON and contains these values. */
94
+ bodyJson?: unknown;
95
+ }
96
+
97
+ export interface Case {
98
+ id: string;
99
+ description: string;
100
+ tags: string[];
101
+ op: keyof typeof OPS;
102
+ input: Record<string, unknown>;
103
+ expect: CaseExpect;
104
+ /** Set by loadCases: the suite directory and the file. */
105
+ suite: 'rules' | 'static' | 'functions';
106
+ file: string;
107
+ }
108
+
109
+ export interface CaseResult {
110
+ id: string;
111
+ op: string;
112
+ tags: string[];
113
+ file: string;
114
+ status: 'passed' | 'failed' | 'skipped';
115
+ failures: string[];
116
+ reason?: string;
117
+ }
118
+
119
+ export interface RunResult {
120
+ passed: number;
121
+ failed: number;
122
+ skipped: number;
123
+ cases: CaseResult[];
124
+ }
125
+
126
+ export const VECTORS_DIR: string;
127
+ export const SUITE_TAGS: Array<'rules' | 'static' | 'functions'>;
128
+ export const TAGS: string[];
129
+ export const OPS: Record<'matchRule' | 'serveStatic' | 'runFunction' | 'serveSite', (input: Record<string, unknown>) => unknown[]>;
130
+ export function adapterArgs(op: string, input: Record<string, unknown>): unknown[];
131
+ export function loadCases(options?: { dir?: string }): Promise<Case[]>;
132
+ export function selectCases(cases: Case[], tags?: string[]): Case[];
133
+ export function checkResult(expect: CaseExpect, actual: unknown): string[];
134
+ export function run(options: { adapter: Adapter; tags?: string[]; cases?: Case[] }): Promise<RunResult>;
package/src/cli.js ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * edge-conformance --adapter <module> [--tags rules,static,functions] [--json]
4
+ * The adapter module exports createAdapter() (named or default).
5
+ */
6
+
7
+ import path from 'node:path';
8
+ import { pathToFileURL } from 'node:url';
9
+ import { parseArgs } from 'node:util';
10
+ import { run } from './index.js';
11
+
12
+ const USAGE = 'Usage: edge-conformance --adapter <module> [--tags rules,static,functions] [--json]';
13
+
14
+ function parse(argv) {
15
+ const { values } = parseArgs({
16
+ args: argv,
17
+ options: {
18
+ adapter: { type: 'string' },
19
+ tags: { type: 'string' },
20
+ json: { type: 'boolean', default: false }
21
+ }
22
+ });
23
+ return values;
24
+ }
25
+
26
+ async function loadAdapter(file) {
27
+ const mod = await import(pathToFileURL(path.resolve(file)).href);
28
+ const create = mod.createAdapter || mod.default;
29
+ if (typeof create !== 'function') throw new Error(`${file} does not export createAdapter()`);
30
+ return create();
31
+ }
32
+
33
+ function printText(result) {
34
+ for (const item of result.cases) {
35
+ if (item.status === 'failed') {
36
+ console.log(`FAIL ${item.id} (${item.file})`);
37
+ for (const failure of item.failures) console.log(` ${failure}`);
38
+ } else if (item.status === 'skipped') {
39
+ console.log(`SKIP ${item.id}: ${item.reason}`);
40
+ }
41
+ }
42
+ console.log(`passed ${result.passed}, failed ${result.failed}, skipped ${result.skipped}`);
43
+ }
44
+
45
+ async function main() {
46
+ let options;
47
+ try {
48
+ options = parse(process.argv.slice(2));
49
+ } catch (err) {
50
+ console.error(`${err.message}\n${USAGE}`);
51
+ return 2;
52
+ }
53
+ if (!options.adapter) {
54
+ console.error(USAGE);
55
+ return 2;
56
+ }
57
+ const tags = options.tags ? options.tags.split(',').map((tag) => tag.trim()).filter(Boolean) : undefined;
58
+ const result = await run({ adapter: await loadAdapter(options.adapter), tags });
59
+ if (options.json) console.log(JSON.stringify(result, null, 2));
60
+ else printText(result);
61
+ return result.failed > 0 ? 1 : 0;
62
+ }
63
+
64
+ process.exitCode = await main();