@sanity/workflow-engine-test 0.3.1 → 0.4.1

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/dist/index.d.cts CHANGED
@@ -51,7 +51,7 @@ export declare type Bench = BenchState &
51
51
 
52
52
  declare type BenchCompleteEffectArgs = Omit<
53
53
  CompleteEffectArgs,
54
- "client" | "tags" | "workflowResource" | "access"
54
+ "client" | "tag" | "workflowResource" | "access"
55
55
  > & {
56
56
  access?: WorkflowAccess;
57
57
  /** Shortcut for `access.actor`. */
@@ -60,7 +60,7 @@ declare type BenchCompleteEffectArgs = Omit<
60
60
 
61
61
  declare type BenchEvaluateArgs = Omit<
62
62
  EvaluateArgs,
63
- "client" | "tags" | "workflowResource" | "access"
63
+ "client" | "tag" | "workflowResource" | "access"
64
64
  > & {
65
65
  access?: WorkflowAccess;
66
66
  /** Shortcut for `access.actor`. */
@@ -71,7 +71,7 @@ declare type BenchEvaluateArgs = Omit<
71
71
 
72
72
  declare type BenchFireActionArgs = Omit<
73
73
  FireActionArgs,
74
- "client" | "tags" | "workflowResource" | "access"
74
+ "client" | "tag" | "workflowResource" | "access"
75
75
  > & {
76
76
  access?: WorkflowAccess;
77
77
  /** Shortcut for `access.actor`. */
@@ -82,7 +82,7 @@ declare type BenchFireActionArgs = Omit<
82
82
 
83
83
  declare type BenchStartInstanceArgs = Omit<
84
84
  StartInstanceArgs,
85
- "client" | "tags" | "workflowResource" | "access"
85
+ "client" | "tag" | "workflowResource" | "access"
86
86
  > & {
87
87
  access?: WorkflowAccess;
88
88
  /** Shortcut for `access.actor`. */
@@ -129,7 +129,7 @@ declare interface BenchState {
129
129
 
130
130
  declare type BenchTickArgs = Omit<
131
131
  OperationArgs,
132
- "client" | "tags" | "workflowResource" | "access"
132
+ "client" | "tag" | "workflowResource" | "access"
133
133
  > & {
134
134
  access?: WorkflowAccess;
135
135
  /** Shortcut for `access.actor`. */
@@ -158,7 +158,7 @@ declare interface CallRecord {
158
158
 
159
159
  /**
160
160
  * Create a fresh bench. By default the bench is fully isolated — two
161
- * `createBench()` calls have no shared state. Pass `client` + `tags`
161
+ * `createBench()` calls have no shared state. Pass `client` + `tag`
162
162
  * to two benches to share a store and exercise tag scoping.
163
163
  */
164
164
  export declare function createBench(options?: CreateBenchOptions): Bench;
@@ -202,18 +202,19 @@ export declare interface CreateBenchOptions {
202
202
  */
203
203
  accessControl?: TestClientAccessControl;
204
204
  /**
205
- * Engine-scope tags. Defaults to `["bench"]`. Pass disjoint sets to two
206
- * benches sharing a `client` to assert multi-tenant isolation; pass an
207
- * overlapping set to assert visibility through a shared tag.
205
+ * Engine-scope environment partition. Defaults to `"bench"`. Pass
206
+ * different tags to two benches sharing a `client` to assert partition
207
+ * isolation; pass the same tag to assert visibility through a shared
208
+ * partition.
208
209
  *
209
- * Tags must be ASCII lowercase + digits + dashes, no leading dash,
210
+ * The tag must be ASCII lowercase + digits + dashes, no leading dash,
210
211
  * no dots — validated at construction.
211
212
  */
212
- tags?: string[];
213
+ tag?: string;
213
214
  /**
214
215
  * Shared TestClient. If omitted, the bench creates its own — two
215
216
  * benches without a shared client are completely isolated, regardless
216
- * of tags. Pass the same client to two benches to test tag-scoped
217
+ * of tag. Pass the same client to two benches to test tag-scoped
217
218
  * visibility across a shared store.
218
219
  */
219
220
  client?: TestClient;
@@ -263,10 +264,10 @@ declare interface DocumentBody {
263
264
 
264
265
  declare type DocumentValuePermission = "create" | "read" | "update";
265
266
 
266
- /** Engine-call wrappers that inject the bench-owned client + tags + access. */
267
+ /** Engine-call wrappers that inject the bench-owned client + tag + access. */
267
268
  declare type EngineWrappers = {
268
269
  deployDefinitions: (
269
- args: Omit<DeployDefinitionsArgs, "client" | "tags" | "workflowResource">,
270
+ args: Omit<DeployDefinitionsArgs, "client" | "tag" | "workflowResource">,
270
271
  ) => Promise<DeployDefinitionsResult>;
271
272
  startInstance: (args: BenchStartInstanceArgs) => Promise<WorkflowInstance>;
272
273
  fireAction: (args: BenchFireActionArgs) => Promise<DispatchResult>;
@@ -500,10 +501,9 @@ declare type Perspective = "raw" | "published" | "drafts" | string[];
500
501
  declare type QueryHelpers = {
501
502
  /**
502
503
  * Run an arbitrary GROQ query through `workflow.query`. The query MUST
503
- * filter on the auto-injected `$engineTags` param (e.g.
504
- * `*[... && count(tags[@ in $engineTags]) > 0]`) or it throws the
505
- * engine refuses to run a query that could read across tenant tags.
506
- * Caller is responsible for narrowing the result.
504
+ * filter on the auto-injected `$tag` param (e.g. `*[... && tag == $tag]`)
505
+ * or it throws the engine refuses to run a query that could read
506
+ * across partitions. Caller is responsible for narrowing the result.
507
507
  */
508
508
  query: <T = unknown>(
509
509
  groq: string,
package/dist/index.d.ts CHANGED
@@ -51,7 +51,7 @@ export declare type Bench = BenchState &
51
51
 
52
52
  declare type BenchCompleteEffectArgs = Omit<
53
53
  CompleteEffectArgs,
54
- "client" | "tags" | "workflowResource" | "access"
54
+ "client" | "tag" | "workflowResource" | "access"
55
55
  > & {
56
56
  access?: WorkflowAccess;
57
57
  /** Shortcut for `access.actor`. */
@@ -60,7 +60,7 @@ declare type BenchCompleteEffectArgs = Omit<
60
60
 
61
61
  declare type BenchEvaluateArgs = Omit<
62
62
  EvaluateArgs,
63
- "client" | "tags" | "workflowResource" | "access"
63
+ "client" | "tag" | "workflowResource" | "access"
64
64
  > & {
65
65
  access?: WorkflowAccess;
66
66
  /** Shortcut for `access.actor`. */
@@ -71,7 +71,7 @@ declare type BenchEvaluateArgs = Omit<
71
71
 
72
72
  declare type BenchFireActionArgs = Omit<
73
73
  FireActionArgs,
74
- "client" | "tags" | "workflowResource" | "access"
74
+ "client" | "tag" | "workflowResource" | "access"
75
75
  > & {
76
76
  access?: WorkflowAccess;
77
77
  /** Shortcut for `access.actor`. */
@@ -82,7 +82,7 @@ declare type BenchFireActionArgs = Omit<
82
82
 
83
83
  declare type BenchStartInstanceArgs = Omit<
84
84
  StartInstanceArgs,
85
- "client" | "tags" | "workflowResource" | "access"
85
+ "client" | "tag" | "workflowResource" | "access"
86
86
  > & {
87
87
  access?: WorkflowAccess;
88
88
  /** Shortcut for `access.actor`. */
@@ -129,7 +129,7 @@ declare interface BenchState {
129
129
 
130
130
  declare type BenchTickArgs = Omit<
131
131
  OperationArgs,
132
- "client" | "tags" | "workflowResource" | "access"
132
+ "client" | "tag" | "workflowResource" | "access"
133
133
  > & {
134
134
  access?: WorkflowAccess;
135
135
  /** Shortcut for `access.actor`. */
@@ -158,7 +158,7 @@ declare interface CallRecord {
158
158
 
159
159
  /**
160
160
  * Create a fresh bench. By default the bench is fully isolated — two
161
- * `createBench()` calls have no shared state. Pass `client` + `tags`
161
+ * `createBench()` calls have no shared state. Pass `client` + `tag`
162
162
  * to two benches to share a store and exercise tag scoping.
163
163
  */
164
164
  export declare function createBench(options?: CreateBenchOptions): Bench;
@@ -202,18 +202,19 @@ export declare interface CreateBenchOptions {
202
202
  */
203
203
  accessControl?: TestClientAccessControl;
204
204
  /**
205
- * Engine-scope tags. Defaults to `["bench"]`. Pass disjoint sets to two
206
- * benches sharing a `client` to assert multi-tenant isolation; pass an
207
- * overlapping set to assert visibility through a shared tag.
205
+ * Engine-scope environment partition. Defaults to `"bench"`. Pass
206
+ * different tags to two benches sharing a `client` to assert partition
207
+ * isolation; pass the same tag to assert visibility through a shared
208
+ * partition.
208
209
  *
209
- * Tags must be ASCII lowercase + digits + dashes, no leading dash,
210
+ * The tag must be ASCII lowercase + digits + dashes, no leading dash,
210
211
  * no dots — validated at construction.
211
212
  */
212
- tags?: string[];
213
+ tag?: string;
213
214
  /**
214
215
  * Shared TestClient. If omitted, the bench creates its own — two
215
216
  * benches without a shared client are completely isolated, regardless
216
- * of tags. Pass the same client to two benches to test tag-scoped
217
+ * of tag. Pass the same client to two benches to test tag-scoped
217
218
  * visibility across a shared store.
218
219
  */
219
220
  client?: TestClient;
@@ -263,10 +264,10 @@ declare interface DocumentBody {
263
264
 
264
265
  declare type DocumentValuePermission = "create" | "read" | "update";
265
266
 
266
- /** Engine-call wrappers that inject the bench-owned client + tags + access. */
267
+ /** Engine-call wrappers that inject the bench-owned client + tag + access. */
267
268
  declare type EngineWrappers = {
268
269
  deployDefinitions: (
269
- args: Omit<DeployDefinitionsArgs, "client" | "tags" | "workflowResource">,
270
+ args: Omit<DeployDefinitionsArgs, "client" | "tag" | "workflowResource">,
270
271
  ) => Promise<DeployDefinitionsResult>;
271
272
  startInstance: (args: BenchStartInstanceArgs) => Promise<WorkflowInstance>;
272
273
  fireAction: (args: BenchFireActionArgs) => Promise<DispatchResult>;
@@ -500,10 +501,9 @@ declare type Perspective = "raw" | "published" | "drafts" | string[];
500
501
  declare type QueryHelpers = {
501
502
  /**
502
503
  * Run an arbitrary GROQ query through `workflow.query`. The query MUST
503
- * filter on the auto-injected `$engineTags` param (e.g.
504
- * `*[... && count(tags[@ in $engineTags]) > 0]`) or it throws the
505
- * engine refuses to run a query that could read across tenant tags.
506
- * Caller is responsible for narrowing the result.
504
+ * filter on the auto-injected `$tag` param (e.g. `*[... && tag == $tag]`)
505
+ * or it throws the engine refuses to run a query that could read
506
+ * across partitions. Caller is responsible for narrowing the result.
507
507
  */
508
508
  query: <T = unknown>(
509
509
  groq: string,
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { guardsForResource, denyingGuards, MutationGuardDeniedError, workflow, WORKFLOW_INSTANCE_TYPE, tagScopeFilter, effectsContextMap, validateTags } from "@sanity/workflow-engine";
1
+ import { guardsForResource, denyingGuards, MutationGuardDeniedError, workflow, WORKFLOW_INSTANCE_TYPE, tagScopeFilter, effectsContextMap, validateTag } from "@sanity/workflow-engine";
2
2
  import require$$0 from "tty";
3
3
  import require$$1 from "util";
4
4
  function escapeRegExp(string2) {
@@ -5132,10 +5132,10 @@ function createQueryHelpers(scope) {
5132
5132
  };
5133
5133
  }
5134
5134
  function createReadHelpers(scope) {
5135
- const { client, tags } = scope, intersectsTags = (docTags) => docTags !== void 0 && tags.some((t) => docTags.includes(t)), getInstance = async (instanceId) => {
5135
+ const { client, tag } = scope, getInstance = async (instanceId) => {
5136
5136
  const doc = await client.getDocument(instanceId);
5137
5137
  if (!doc) throw new Error(`Workflow instance ${instanceId} not found`);
5138
- if (!intersectsTags(doc.tags))
5138
+ if (doc.tag !== tag)
5139
5139
  throw new Error(`Workflow instance ${instanceId} not visible to this engine (tag mismatch)`);
5140
5140
  return doc;
5141
5141
  };
@@ -5164,7 +5164,7 @@ function createReadHelpers(scope) {
5164
5164
  `*[_type == "${WORKFLOW_INSTANCE_TYPE}"
5165
5165
  && state[_type == "doc.ref" && name == $entry][0].value.id == $ref
5166
5166
  && ${tagScopeFilter()}] | order(startedAt asc)`,
5167
- { ref: subjectRef, entry: entryName, engineTags: tags }
5167
+ { ref: subjectRef, entry: entryName, tag }
5168
5168
  )
5169
5169
  ),
5170
5170
  instancesByStage: async (workflowName, stage, queryOptions) => {
@@ -5172,16 +5172,16 @@ function createReadHelpers(scope) {
5172
5172
  return client.fetch(
5173
5173
  `*[_type == "${WORKFLOW_INSTANCE_TYPE}" && definition == $wf && currentStage == $stage && ${tagScopeFilter()}${filter}]
5174
5174
  | order(startedAt asc)`,
5175
- { wf: workflowName, stage, engineTags: tags }
5175
+ { wf: workflowName, stage, tag }
5176
5176
  );
5177
5177
  },
5178
5178
  snapshot: () => client.snapshot()
5179
5179
  };
5180
5180
  }
5181
5181
  function createBench(options = {}) {
5182
- const tags = options.tags ?? ["bench"];
5183
- validateTags(tags);
5184
- const workflowResource = options.workflowResource ?? DEFAULT_WORKFLOW_RESOURCE, client = resolveBenchClient(options), scope = { client, tags, workflowResource }, access = resolveBenchAccess(options);
5182
+ const tag = options.tag ?? "bench";
5183
+ validateTag(tag);
5184
+ const workflowResource = options.workflowResource ?? DEFAULT_WORKFLOW_RESOURCE, client = resolveBenchClient(options), scope = { client, tag, workflowResource }, access = resolveBenchAccess(options);
5185
5185
  let frozenNow = options.now !== void 0 ? assertIsoInstant(options.now) : void 0;
5186
5186
  const clock = () => frozenNow ?? (/* @__PURE__ */ new Date()).toISOString();
5187
5187
  return {