@onlyflows/servicenow-mcp 2.1.0 → 2.2.0-dev.2

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.
Files changed (133) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +14 -7
  3. package/dist/atf-config.d.ts +72 -0
  4. package/dist/atf-config.d.ts.map +1 -0
  5. package/dist/atf-config.js +179 -0
  6. package/dist/atf-config.js.map +1 -0
  7. package/dist/atf-form.d.ts +27 -0
  8. package/dist/atf-form.d.ts.map +1 -0
  9. package/dist/atf-form.js +110 -0
  10. package/dist/atf-form.js.map +1 -0
  11. package/dist/atf-policy.d.ts +46 -0
  12. package/dist/atf-policy.d.ts.map +1 -0
  13. package/dist/atf-policy.js +85 -0
  14. package/dist/atf-policy.js.map +1 -0
  15. package/dist/atf-result-cache.d.ts +108 -0
  16. package/dist/atf-result-cache.d.ts.map +1 -0
  17. package/dist/atf-result-cache.js +273 -0
  18. package/dist/atf-result-cache.js.map +1 -0
  19. package/dist/client.d.ts +6 -2
  20. package/dist/client.d.ts.map +1 -1
  21. package/dist/client.js +35 -7
  22. package/dist/client.js.map +1 -1
  23. package/dist/config.d.ts +8 -0
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/config.js +15 -0
  26. package/dist/config.js.map +1 -1
  27. package/dist/execution-context.d.ts +7 -3
  28. package/dist/execution-context.d.ts.map +1 -1
  29. package/dist/execution-context.js +6 -2
  30. package/dist/execution-context.js.map +1 -1
  31. package/dist/field-policy.d.ts.map +1 -1
  32. package/dist/field-policy.js +48 -1
  33. package/dist/field-policy.js.map +1 -1
  34. package/dist/http-entrypoint.d.ts.map +1 -1
  35. package/dist/http-entrypoint.js +3 -0
  36. package/dist/http-entrypoint.js.map +1 -1
  37. package/dist/http-observability.js +2 -1
  38. package/dist/http-observability.js.map +1 -1
  39. package/dist/index.js +3 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/metadata-cache.d.ts.map +1 -1
  42. package/dist/metadata-cache.js +1 -0
  43. package/dist/metadata-cache.js.map +1 -1
  44. package/dist/profile-manager.d.ts +12 -0
  45. package/dist/profile-manager.d.ts.map +1 -1
  46. package/dist/profile-manager.js +30 -3
  47. package/dist/profile-manager.js.map +1 -1
  48. package/dist/setup-prompts.js +1 -1
  49. package/dist/setup-prompts.js.map +1 -1
  50. package/dist/setup.d.ts.map +1 -1
  51. package/dist/setup.js +11 -4
  52. package/dist/setup.js.map +1 -1
  53. package/dist/structured-query.d.ts +2 -2
  54. package/dist/tool-table-access.js +2 -4
  55. package/dist/tool-table-access.js.map +1 -1
  56. package/dist/tools/aggregate.d.ts +1 -1
  57. package/dist/tools/atf-author-module.d.ts +98 -0
  58. package/dist/tools/atf-author-module.d.ts.map +1 -0
  59. package/dist/tools/atf-author-module.js +140 -0
  60. package/dist/tools/atf-author-module.js.map +1 -0
  61. package/dist/tools/atf-contracts.d.ts +734 -0
  62. package/dist/tools/atf-contracts.d.ts.map +1 -0
  63. package/dist/tools/atf-contracts.js +30 -0
  64. package/dist/tools/atf-contracts.js.map +1 -0
  65. package/dist/tools/atf-readiness-module.d.ts +2 -0
  66. package/dist/tools/atf-readiness-module.d.ts.map +1 -0
  67. package/dist/tools/atf-readiness-module.js +153 -0
  68. package/dist/tools/atf-readiness-module.js.map +1 -0
  69. package/dist/tools/atf-renderers.d.ts +2 -0
  70. package/dist/tools/atf-renderers.d.ts.map +1 -0
  71. package/dist/tools/atf-renderers.js +39 -0
  72. package/dist/tools/atf-renderers.js.map +1 -0
  73. package/dist/tools/atf-results-module.d.ts +2 -0
  74. package/dist/tools/atf-results-module.d.ts.map +1 -0
  75. package/dist/tools/atf-results-module.js +58 -0
  76. package/dist/tools/atf-results-module.js.map +1 -0
  77. package/dist/tools/atf-run-module.d.ts +3 -0
  78. package/dist/tools/atf-run-module.d.ts.map +1 -0
  79. package/dist/tools/atf-run-module.js +96 -0
  80. package/dist/tools/atf-run-module.js.map +1 -0
  81. package/dist/tools/atf-shared.d.ts +31 -0
  82. package/dist/tools/atf-shared.d.ts.map +1 -0
  83. package/dist/tools/atf-shared.js +182 -0
  84. package/dist/tools/atf-shared.js.map +1 -0
  85. package/dist/tools/atf-step-catalog.d.ts +96 -0
  86. package/dist/tools/atf-step-catalog.d.ts.map +1 -0
  87. package/dist/tools/atf-step-catalog.js +237 -0
  88. package/dist/tools/atf-step-catalog.js.map +1 -0
  89. package/dist/tools/atf-step-definitions.json +533 -0
  90. package/dist/tools/atf.d.ts +5 -5
  91. package/dist/tools/atf.d.ts.map +1 -1
  92. package/dist/tools/atf.js +4 -234
  93. package/dist/tools/atf.js.map +1 -1
  94. package/dist/tools/attach.d.ts +1 -1
  95. package/dist/tools/batch.d.ts +2 -2
  96. package/dist/tools/catalog.d.ts +2 -3
  97. package/dist/tools/catalog.d.ts.map +1 -1
  98. package/dist/tools/catalog.js +9 -2
  99. package/dist/tools/catalog.js.map +1 -1
  100. package/dist/tools/discover.d.ts +1 -1
  101. package/dist/tools/index.d.ts +3 -3
  102. package/dist/tools/index.d.ts.map +1 -1
  103. package/dist/tools/index.js +26 -17
  104. package/dist/tools/index.js.map +1 -1
  105. package/dist/tools/markdown.d.ts +77 -0
  106. package/dist/tools/markdown.d.ts.map +1 -0
  107. package/dist/tools/markdown.js +279 -0
  108. package/dist/tools/markdown.js.map +1 -0
  109. package/dist/tools/nl.d.ts +2 -2
  110. package/dist/tools/relationships.d.ts +2 -2
  111. package/dist/tools/result-envelope.d.ts +832 -24
  112. package/dist/tools/result-envelope.d.ts.map +1 -1
  113. package/dist/tools/result-envelope.js +103 -3
  114. package/dist/tools/result-envelope.js.map +1 -1
  115. package/dist/tools/syslog.d.ts +2 -2
  116. package/dist/tools/tool-module.d.ts +13 -3
  117. package/dist/tools/tool-module.d.ts.map +1 -1
  118. package/dist/tools/tool-module.js +1 -0
  119. package/dist/tools/tool-module.js.map +1 -1
  120. package/dist/version.d.ts +1 -1
  121. package/dist/version.d.ts.map +1 -1
  122. package/dist/version.js +1 -1
  123. package/dist/version.js.map +1 -1
  124. package/docs/ATF-WORKFLOW.md +115 -0
  125. package/docs/CLIENT-SETUP.md +2 -2
  126. package/docs/CONTAINER-DEPLOYMENT.md +11 -0
  127. package/docs/CROSS-CLIENT-RELEASE-MATRIX.md +1 -1
  128. package/docs/PROFILE-CREDENTIALS.md +65 -0
  129. package/docs/RELEASE-VALIDATION.md +29 -2
  130. package/docs/TESTING-OAUTH.md +1 -1
  131. package/docs/V2-MIGRATION.md +4 -4
  132. package/package.json +4 -2
  133. package/scripts/release-validate.mjs +14 -4
package/CHANGELOG.md CHANGED
@@ -5,6 +5,61 @@ All notable changes to this project are documented here.
5
5
  The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.2.0-dev.2] — 2026-09-15
9
+
10
+ ### Added
11
+
12
+ - ATF readiness checks, CI/CD suite execution with bounded polling, detailed
13
+ results, persistent history and comparisons between runs.
14
+ - A verified catalog of 13 typed ATF steps, including REST headers/query maps
15
+ and references to outputs from earlier steps in the same test.
16
+ - Native authenticated ATF form input saving and stored-value verification,
17
+ without installing a scoped application or changing ServiceNow ACLs.
18
+ - Authoring grants now include input mappings and required metadata reads.
19
+
20
+ ### Fixed
21
+
22
+ - Global scope creation accepts the platform's `global` identifier; new steps
23
+ inherit their parent test's scope.
24
+ - Plugin readiness recognizes the platform's `active` choice value.
25
+ - Step input verification handles stored boolean values and enforces security
26
+ by default for record queries and validation.
27
+ - Failed step authoring performs bounded cleanup even after request cancellation
28
+ and reports remaining input or mapping records.
29
+
30
+ ### Validation
31
+
32
+ - PDI validation in Global: all 13 types authored and read back; server-side
33
+ assertions, record-output chaining, REST unauthorized-response checks, results,
34
+ failure details, history and comparisons verified. Temporary records removed.
35
+ - Browser-driven steps were authored but their execution requires an ATF browser
36
+ runner. Authenticated REST requests need their own ATF request credentials.
37
+ - This remains a dev prerelease; native forms must be verified against each
38
+ supported ServiceNow version.
39
+
40
+ ## [2.2.0-dev.1] — 2026-09-14
41
+
42
+ ### Added
43
+
44
+ - Tag-driven dev prereleases publish to the npm `dev` channel while stable
45
+ releases continue to publish to `latest`.
46
+
47
+ - `sn_atf_author` creates tests, suites, and ordered suite memberships under
48
+ explicit table and field grants. Failed attempts return a structured rollback
49
+ report and identify uncertain inserts that require inspection before retrying.
50
+ - `setup grant --atf` binds the five ATF authoring tables to `sn_atf_author`
51
+ without enabling execution or script steps.
52
+ - Per-profile ATF configuration, opt-in execution-policy infrastructure, and
53
+ escaping-first readable tool renderers.
54
+ - An identity-bound ATF result-cache library with atomic writes, concurrent-writer
55
+ locking, bounded summaries, private storage and memory fallback. Execution and
56
+ results tools will connect to this library in a subsequent change.
57
+
58
+ ### Fixed
59
+
60
+ - ATF suite-result table policy fields use `rolled_up_test_*`, matching the
61
+ platform fixtures rather than the CI/CD response spelling.
62
+
8
63
  ## [2.1.0] — 2026-09
9
64
 
10
65
  > **Read this before upgrading if any profile grants `writeTables: ["*"]`, or
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <!-- Logo placeholder -->
4
4
  <!-- ![ServiceNow MCP Server](banner.png) -->
5
5
 
6
- **The most comprehensive ServiceNow MCP server.** 19 tools for full CRUD, append-only incident journals, CMDB graph traversal, ATF testing, multi-instance profiles, and more.
6
+ **The most comprehensive ServiceNow MCP server.** 23 tools for full CRUD, append-only incident journals, CMDB graph traversal, ATF testing, multi-instance profiles, and more.
7
7
 
8
8
  Built by [OnlyFlows](https://onlyflows.tech) · Published by [@onlyflowstech](https://github.com/onlyflowstech)
9
9
 
@@ -492,11 +492,11 @@ deny-by-default table and tool policy:
492
492
  | System log queries | ❌ | ✅ |
493
493
  | Code search across artifacts | ❌ | ✅ |
494
494
  | Table/app/plugin discovery | ❌ | ✅ |
495
- | ATF test execution | ❌ | 🚧 listing/results available; execution currently policy-denied |
495
+ | ATF test execution | ❌ | ✅ suite execution with explicit profile grant |
496
496
  | Natural language interface | ❌ | 🚧 currently policy-denied pending a typed access plan |
497
497
  | Background scripts | ❌ | 🚧 on the [roadmap](#roadmap) (SNS-39) |
498
498
  | Multi-instance profiles | ❌ | ✅ (named profiles, per-call override) |
499
- | **Total tools** | **1–3** | **19** |
499
+ | **Total tools** | **1–3** | **23** |
500
500
 
501
501
  ---
502
502
 
@@ -625,7 +625,11 @@ in this section is needed to use this server.
625
625
 
626
626
  | Tool | Description |
627
627
  |------|-------------|
628
- | `sn_atf` | List ATF tests/suites and get results; `run`/`run-suite` currently fail closed |
628
+ | `sn_atf_author` | Create tests/suites, ordered memberships and validated typed steps |
629
+ | `sn_atf` | Legacy test/suite listing and results; execution redirects to `sn_atf_run` |
630
+ | `sn_atf_readiness` | Check plugins, properties, runner availability and permissions |
631
+ | `sn_atf_run` | Execute a suite through CI/CD with bounded polling |
632
+ | `sn_atf_results` | Fetch results, cached history and comparisons |
629
633
  | `sn_nl` | Currently fails closed until natural-language composition emits a complete typed access plan |
630
634
 
631
635
  `sn_script` (background script execution) shipped in 1.0.0 as an unimplemented
@@ -926,8 +930,11 @@ complete. File-backed profile example:
926
930
  }
927
931
  }
928
932
  ```
929
- `sn_nl` and ATF `run`/`run-suite` currently fail closed because they do not emit
930
- a complete typed side-effect plan; use the corresponding typed tool instead.
933
+ `sn_nl` remains denied without a complete typed side-effect plan. Legacy ATF
934
+ `run`/`run-suite` return migration guidance; use `sn_atf_run` with an explicit
935
+ `atf.execute` profile grant. Typed ATF steps use the authenticated native form
936
+ to save and verify inputs and output references without ACL changes or an
937
+ installed application. See [ATF workflow](docs/ATF-WORKFLOW.md).
931
938
  Incident journal fields are append-only: generic `sn_update` rejects `comments`
932
939
  and `work_notes` before credentials or client creation. Use
933
940
  `sn_incident_add_comment` or `sn_incident_add_work_note` with exactly
@@ -1005,7 +1012,7 @@ This server is designed for production use with multiple safety layers:
1005
1012
  - **Delete operations** require explicit `confirm: true`
1006
1013
  - **Batch operations** run in dry-run mode by default — shows match count without making changes
1007
1014
  - **Bulk operations** require `confirm: true` to leave dry-run mode
1008
- - **Unclassified composition is denied** — `sn_nl` and ATF execution do not run until they can emit complete typed access plans
1015
+ - **Unclassified composition is denied** — `sn_nl` requires a complete typed access plan; ATF suite execution requires a separate explicit `atf.execute` grant
1009
1016
  - **Table access is deny-by-default** with independent exact read/write allowlists and non-configurable sensitive-table denials
1010
1017
  - **User input is neutralized** before interpolation into encoded queries (`^` is stripped from filter values — ServiceNow's query syntax has no escape sequence)
1011
1018
 
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Per-profile Automated Test Framework (ATF) settings.
3
+ *
4
+ * Two kinds of setting live here, and they are resolved differently:
5
+ *
6
+ * - Grants (`execute`, `allowScriptSteps`) widen what a caller may make the
7
+ * instance do. Like `tableAccess`, they come only from the profile itself;
8
+ * the SN_ATF_* environment variables supply them solely to the explicitly
9
+ * named environment-only profile. A process-wide variable never grants ATF
10
+ * execution to every profile in config.json.
11
+ * - Result-cache settings (`resultCacheSize`, `resultCacheDir`) are ordinary
12
+ * tuning. Like `metadataCache`, the profile value wins and the environment
13
+ * is the fallback for every profile.
14
+ *
15
+ * Every error message names the offending key and never echoes its value.
16
+ *
17
+ * @module atf-config
18
+ */
19
+ export declare const DEFAULT_ATF_RESULT_CACHE_SIZE = 10;
20
+ export declare const MAX_ATF_RESULT_CACHE_SIZE = 100;
21
+ /** The `atf` block as written in a profile or read from the environment. */
22
+ export interface AtfConfigInput {
23
+ /** Permit ATF execution tools to run suites (default false). */
24
+ readonly execute?: boolean;
25
+ /** Runs retained per suite in the local result cache (1-100, default 10). */
26
+ readonly resultCacheSize?: number;
27
+ /** Absolute directory for the local result cache (default chosen by the cache). */
28
+ readonly resultCacheDir?: string;
29
+ /** Permit authoring ATF steps that run server-side script (default false). */
30
+ readonly allowScriptSteps?: boolean;
31
+ }
32
+ /** Fully resolved, frozen ATF settings for one profile. */
33
+ export interface AtfConfig {
34
+ readonly execute: boolean;
35
+ readonly allowScriptSteps: boolean;
36
+ readonly resultCacheSize: number;
37
+ readonly resultCacheDir?: string;
38
+ }
39
+ /**
40
+ * The non-secret slice a tool handler receives. Execution grants are not here:
41
+ * they are enforced before the handler runs, from the resolved policy.
42
+ */
43
+ export interface AtfHandlerSettings {
44
+ readonly resultCacheSize: number;
45
+ readonly resultCacheDir?: string;
46
+ }
47
+ /** Operator-authored configuration error; the message is safe to display. */
48
+ export declare class AtfConfigurationError extends Error {
49
+ readonly name = "AtfConfigurationError";
50
+ }
51
+ interface AtfEnvironment {
52
+ readonly SN_ATF_EXECUTE?: string;
53
+ readonly SN_ATF_RESULT_CACHE_SIZE?: string;
54
+ readonly SN_ATF_RESULT_CACHE_DIR?: string;
55
+ readonly SN_ATF_ALLOW_SCRIPT_STEPS?: string;
56
+ }
57
+ /** Read the SN_ATF_* variables, keeping only the keys that are set. */
58
+ export declare function atfConfigFromEnvironment(environment?: AtfEnvironment): AtfConfigInput;
59
+ /**
60
+ * Validate a profile's `atf` block and return a frozen copy holding only the
61
+ * keys it states. Throws AtfConfigurationError on any unsupported shape.
62
+ */
63
+ export declare function validateAtfConfigInput(candidate: unknown): AtfConfigInput;
64
+ /**
65
+ * Merge a profile's `atf` block with the environment. Grants come from the
66
+ * profile alone; cache settings fall back to the environment, then defaults.
67
+ */
68
+ export declare function resolveAtfConfig(profile: AtfConfigInput | undefined, environment: AtfConfigInput): AtfConfig;
69
+ /** Project resolved settings onto what a handler may see. */
70
+ export declare function atfHandlerSettings(config: AtfConfig | undefined): AtfHandlerSettings;
71
+ export {};
72
+ //# sourceMappingURL=atf-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atf-config.d.ts","sourceRoot":"","sources":["../src/atf-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAU7C,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,QAA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AAkB,CAChC,MAAM,EAAE,SAAS,GAAG,SAAS,GAC5B,kBAAkB,CAOpB"}
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ /**
3
+ * Per-profile Automated Test Framework (ATF) settings.
4
+ *
5
+ * Two kinds of setting live here, and they are resolved differently:
6
+ *
7
+ * - Grants (`execute`, `allowScriptSteps`) widen what a caller may make the
8
+ * instance do. Like `tableAccess`, they come only from the profile itself;
9
+ * the SN_ATF_* environment variables supply them solely to the explicitly
10
+ * named environment-only profile. A process-wide variable never grants ATF
11
+ * execution to every profile in config.json.
12
+ * - Result-cache settings (`resultCacheSize`, `resultCacheDir`) are ordinary
13
+ * tuning. Like `metadataCache`, the profile value wins and the environment
14
+ * is the fallback for every profile.
15
+ *
16
+ * Every error message names the offending key and never echoes its value.
17
+ *
18
+ * @module atf-config
19
+ */
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
27
+ }) : (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ }));
31
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) || (function () {
37
+ var ownKeys = function(o) {
38
+ ownKeys = Object.getOwnPropertyNames || function (o) {
39
+ var ar = [];
40
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
41
+ return ar;
42
+ };
43
+ return ownKeys(o);
44
+ };
45
+ return function (mod) {
46
+ if (mod && mod.__esModule) return mod;
47
+ var result = {};
48
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
49
+ __setModuleDefault(result, mod);
50
+ return result;
51
+ };
52
+ })();
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.AtfConfigurationError = exports.MAX_ATF_RESULT_CACHE_SIZE = exports.DEFAULT_ATF_RESULT_CACHE_SIZE = void 0;
55
+ exports.atfConfigFromEnvironment = atfConfigFromEnvironment;
56
+ exports.validateAtfConfigInput = validateAtfConfigInput;
57
+ exports.resolveAtfConfig = resolveAtfConfig;
58
+ exports.atfHandlerSettings = atfHandlerSettings;
59
+ const path = __importStar(require("path"));
60
+ const config_js_1 = require("./config.js");
61
+ exports.DEFAULT_ATF_RESULT_CACHE_SIZE = 10;
62
+ exports.MAX_ATF_RESULT_CACHE_SIZE = 100;
63
+ const MAX_ATF_RESULT_CACHE_DIR_LENGTH = 1024;
64
+ const CONTROL_CHARACTER = /[\u0000-\u001F\u007F]/u;
65
+ const ATF_CONFIG_KEYS = Object.freeze([
66
+ "execute",
67
+ "resultCacheSize",
68
+ "resultCacheDir",
69
+ "allowScriptSteps",
70
+ ]);
71
+ /** Operator-authored configuration error; the message is safe to display. */
72
+ class AtfConfigurationError extends Error {
73
+ name = "AtfConfigurationError";
74
+ }
75
+ exports.AtfConfigurationError = AtfConfigurationError;
76
+ /** Read the SN_ATF_* variables, keeping only the keys that are set. */
77
+ function atfConfigFromEnvironment(environment = process.env) {
78
+ const execute = (0, config_js_1.parseBooleanEnv)(environment.SN_ATF_EXECUTE, "SN_ATF_EXECUTE");
79
+ const allowScriptSteps = (0, config_js_1.parseBooleanEnv)(environment.SN_ATF_ALLOW_SCRIPT_STEPS, "SN_ATF_ALLOW_SCRIPT_STEPS");
80
+ const resultCacheSize = (0, config_js_1.parsePositiveIntegerEnv)(environment.SN_ATF_RESULT_CACHE_SIZE, "SN_ATF_RESULT_CACHE_SIZE", { max: exports.MAX_ATF_RESULT_CACHE_SIZE });
81
+ const rawDirectory = environment.SN_ATF_RESULT_CACHE_DIR;
82
+ const resultCacheDir = rawDirectory === undefined || rawDirectory.trim() === ""
83
+ ? undefined
84
+ : validateResultCacheDir(rawDirectory, "SN_ATF_RESULT_CACHE_DIR");
85
+ return Object.freeze({
86
+ ...(execute === undefined ? {} : { execute }),
87
+ ...(resultCacheSize === undefined ? {} : { resultCacheSize }),
88
+ ...(resultCacheDir === undefined ? {} : { resultCacheDir }),
89
+ ...(allowScriptSteps === undefined ? {} : { allowScriptSteps }),
90
+ });
91
+ }
92
+ /**
93
+ * Validate a profile's `atf` block and return a frozen copy holding only the
94
+ * keys it states. Throws AtfConfigurationError on any unsupported shape.
95
+ */
96
+ function validateAtfConfigInput(candidate) {
97
+ if (typeof candidate !== "object" ||
98
+ candidate === null ||
99
+ Array.isArray(candidate)) {
100
+ throw new AtfConfigurationError("atf must be an object");
101
+ }
102
+ const source = candidate;
103
+ for (const key of Object.keys(source)) {
104
+ if (!ATF_CONFIG_KEYS.includes(key)) {
105
+ throw new AtfConfigurationError(`atf supports only ${ATF_CONFIG_KEYS.join(", ")}`);
106
+ }
107
+ }
108
+ const { execute, resultCacheSize, resultCacheDir, allowScriptSteps } = source;
109
+ if (execute !== undefined && typeof execute !== "boolean") {
110
+ throw new AtfConfigurationError("atf.execute must be true or false");
111
+ }
112
+ if (allowScriptSteps !== undefined && typeof allowScriptSteps !== "boolean") {
113
+ throw new AtfConfigurationError("atf.allowScriptSteps must be true or false");
114
+ }
115
+ if (resultCacheSize !== undefined &&
116
+ (typeof resultCacheSize !== "number" ||
117
+ !Number.isSafeInteger(resultCacheSize) ||
118
+ resultCacheSize < 1 ||
119
+ resultCacheSize > exports.MAX_ATF_RESULT_CACHE_SIZE)) {
120
+ throw new AtfConfigurationError(`atf.resultCacheSize must be an integer between 1 and ${exports.MAX_ATF_RESULT_CACHE_SIZE}`);
121
+ }
122
+ const directory = resultCacheDir === undefined
123
+ ? undefined
124
+ : validateResultCacheDir(resultCacheDir, "atf.resultCacheDir");
125
+ return Object.freeze({
126
+ ...(execute === undefined ? {} : { execute }),
127
+ ...(resultCacheSize === undefined ? {} : { resultCacheSize }),
128
+ ...(directory === undefined ? {} : { resultCacheDir: directory }),
129
+ ...(allowScriptSteps === undefined ? {} : { allowScriptSteps }),
130
+ });
131
+ }
132
+ /**
133
+ * Merge a profile's `atf` block with the environment. Grants come from the
134
+ * profile alone; cache settings fall back to the environment, then defaults.
135
+ */
136
+ function resolveAtfConfig(profile, environment) {
137
+ const resultCacheDir = profile?.resultCacheDir ?? environment.resultCacheDir;
138
+ return Object.freeze({
139
+ execute: profile?.execute === true,
140
+ allowScriptSteps: profile?.allowScriptSteps === true,
141
+ resultCacheSize: profile?.resultCacheSize ??
142
+ environment.resultCacheSize ??
143
+ exports.DEFAULT_ATF_RESULT_CACHE_SIZE,
144
+ ...(resultCacheDir === undefined ? {} : { resultCacheDir }),
145
+ });
146
+ }
147
+ /** Project resolved settings onto what a handler may see. */
148
+ function atfHandlerSettings(config) {
149
+ return Object.freeze({
150
+ resultCacheSize: config?.resultCacheSize ?? exports.DEFAULT_ATF_RESULT_CACHE_SIZE,
151
+ ...(config?.resultCacheDir === undefined
152
+ ? {}
153
+ : { resultCacheDir: config.resultCacheDir }),
154
+ });
155
+ }
156
+ /**
157
+ * Accept only an absolute, normalized directory. The cache opens it later
158
+ * with its own no-symlink checks; this rejects values that are wrong on their
159
+ * face so a typo fails when the profile loads, not on the first ATF run.
160
+ */
161
+ function validateResultCacheDir(value, label) {
162
+ if (typeof value !== "string" || value.length === 0) {
163
+ throw new AtfConfigurationError(`${label} must be a non-empty string`);
164
+ }
165
+ if (value.length > MAX_ATF_RESULT_CACHE_DIR_LENGTH) {
166
+ throw new AtfConfigurationError(`${label} must not exceed ${MAX_ATF_RESULT_CACHE_DIR_LENGTH} characters`);
167
+ }
168
+ if (CONTROL_CHARACTER.test(value)) {
169
+ throw new AtfConfigurationError(`${label} must not contain control characters`);
170
+ }
171
+ if (!path.isAbsolute(value)) {
172
+ throw new AtfConfigurationError(`${label} must be an absolute path`);
173
+ }
174
+ if (value.split(/[\\/]/u).includes("..")) {
175
+ throw new AtfConfigurationError(`${label} must not contain ".." segments`);
176
+ }
177
+ return value;
178
+ }
179
+ //# sourceMappingURL=atf-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atf-config.js","sourceRoot":"","sources":["../src/atf-config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DH,4DAwBC;AAMD,wDA4CC;AAMD,4CAcC;AAGD,gDASC;AAnKD,2CAA6B;AAE7B,2CAAuE;AAE1D,QAAA,6BAA6B,GAAG,EAAE,CAAC;AACnC,QAAA,yBAAyB,GAAG,GAAG,CAAC;AAC7C,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAC7C,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AACnD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,SAAS;IACT,iBAAiB;IACjB,gBAAgB;IAChB,kBAAkB;CACV,CAAC,CAAC;AA+BZ,6EAA6E;AAC7E,MAAa,qBAAsB,SAAQ,KAAK;IACrB,IAAI,GAAG,uBAAuB,CAAC;CACzD;AAFD,sDAEC;AASD,uEAAuE;AACvE,SAAgB,wBAAwB,CACtC,cAA8B,OAAO,CAAC,GAAqB;IAE3D,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,WAAW,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAC9E,MAAM,gBAAgB,GAAG,IAAA,2BAAe,EACtC,WAAW,CAAC,yBAAyB,EACrC,2BAA2B,CAC5B,CAAC;IACF,MAAM,eAAe,GAAG,IAAA,mCAAuB,EAC7C,WAAW,CAAC,wBAAwB,EACpC,0BAA0B,EAC1B,EAAE,GAAG,EAAE,iCAAyB,EAAE,CACnC,CAAC;IACF,MAAM,YAAY,GAAG,WAAW,CAAC,uBAAuB,CAAC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AAK,sCAAsC,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,qBAAqB,CAAC,GAAG,KAAK,2BAA2B,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,qBAAqB,CAAC,GAAG,KAAK,iCAAiC,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { z } from "zod";
2
+ export declare const atfFormInputSchema: z.ZodObject<{
3
+ stepId: z.ZodString;
4
+ testId: z.ZodString;
5
+ configId: z.ZodString;
6
+ scope: z.ZodUnion<[z.ZodString, z.ZodLiteral<"global">]>;
7
+ inputs: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>;
8
+ }, "strict", z.ZodTypeAny, {
9
+ stepId: string;
10
+ testId: string;
11
+ configId: string;
12
+ scope: string;
13
+ inputs: Record<string, string>;
14
+ }, {
15
+ stepId: string;
16
+ testId: string;
17
+ configId: string;
18
+ scope: string;
19
+ inputs: Record<string, string>;
20
+ }>;
21
+ export type AtfFormInput = z.infer<typeof atfFormInputSchema>;
22
+ export declare const ATF_STEP_REFERENCE: RegExp;
23
+ /** Return only the required protocol fields and requested input controls. */
24
+ export declare function prepareAtfForm(html: string, origin: string, candidate: AtfFormInput): URLSearchParams;
25
+ /** Cookies live only for one form load/save pair and never leave the exact origin. */
26
+ export declare function atfFormCookies(headers: Headers): string;
27
+ //# sourceMappingURL=atf-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atf-form.d.ts","sourceRoot":"","sources":["../src/atf-form.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;EAGpB,CAAC;AACZ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,eAAO,MAAM,kBAAkB,QAAuD,CAAC;AAevF,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,GAAG,eAAe,CAkDrG;AACD,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIvD"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ATF_STEP_REFERENCE = exports.atfFormInputSchema = void 0;
4
+ exports.prepareAtfForm = prepareAtfForm;
5
+ exports.atfFormCookies = atfFormCookies;
6
+ /** Native ATF form contract. HTML is parsed as data and never executed. */
7
+ const parse5_1 = require("parse5");
8
+ const zod_1 = require("zod");
9
+ const servicenow_identifiers_js_1 = require("./servicenow-identifiers.js");
10
+ const tool_error_js_1 = require("./tool-error.js");
11
+ exports.atfFormInputSchema = zod_1.z.object({
12
+ stepId: servicenow_identifiers_js_1.serviceNowSysIdSchema, testId: servicenow_identifiers_js_1.serviceNowSysIdSchema, configId: servicenow_identifiers_js_1.serviceNowSysIdSchema, scope: zod_1.z.union([servicenow_identifiers_js_1.serviceNowSysIdSchema, zod_1.z.literal("global")]),
13
+ inputs: zod_1.z.record(zod_1.z.string().regex(/^[a-z][a-z0-9_]{0,79}$/), zod_1.z.string().max(100000)).refine(value => Object.keys(value).length <= 50),
14
+ }).strict();
15
+ exports.ATF_STEP_REFERENCE = /^\{\{step\['[a-f0-9]{32}'\]\.[a-z][a-z0-9_]*\}\}$/u;
16
+ const reject = () => (0, tool_error_js_1.createToolError)("upstream", "do_not_retry");
17
+ function elements(node) {
18
+ const result = [];
19
+ function visit(child) {
20
+ if ("tagName" in child)
21
+ result.push(child);
22
+ if ("childNodes" in child)
23
+ for (const next of child.childNodes)
24
+ visit(next);
25
+ }
26
+ visit(node);
27
+ return result;
28
+ }
29
+ function attr(node, key) { return node.attrs.find(a => a.name === key)?.value; }
30
+ function contents(node) {
31
+ if (node.nodeName === "#text")
32
+ return node.value;
33
+ return "childNodes" in node ? node.childNodes.map(contents).join("") : "";
34
+ }
35
+ /** Return only the required protocol fields and requested input controls. */
36
+ function prepareAtfForm(html, origin, candidate) {
37
+ const input = exports.atfFormInputSchema.parse(candidate);
38
+ const forms = elements((0, parse5_1.parse)(html)).filter(e => e.tagName === "form" && attr(e, "name") === "sys_atf_step.do");
39
+ if (forms.length !== 1)
40
+ throw reject();
41
+ const form = forms[0];
42
+ const target = new URL(attr(form, "action") ?? "", origin + "/sys_atf_step.do");
43
+ if (target.origin !== origin || target.pathname !== "/sys_atf_step.do" || target.search || target.hash || target.username || target.password || attr(form, "method")?.toLowerCase() !== "post")
44
+ throw reject();
45
+ const controls = new Map();
46
+ for (const element of elements(form)) {
47
+ if (!["input", "textarea", "select"].includes(element.tagName))
48
+ continue;
49
+ const name = attr(element, "name");
50
+ if (!name)
51
+ continue;
52
+ const type = attr(element, "type")?.toLowerCase() ?? "text";
53
+ if (["button", "submit", "file", "reset"].includes(type))
54
+ continue;
55
+ const disabled = attr(element, "disabled") !== undefined;
56
+ if (["checkbox", "radio"].includes(type) && attr(element, "checked") === undefined)
57
+ continue;
58
+ let value = attr(element, "value") ?? "";
59
+ if (element.tagName === "textarea")
60
+ value = contents(element);
61
+ if (element.tagName === "select") {
62
+ const options = elements(element).filter(e => e.tagName === "option");
63
+ const option = options.find(e => attr(e, "selected") !== undefined) ?? options[0];
64
+ value = option ? attr(option, "value") ?? contents(option) : "";
65
+ }
66
+ const old = controls.get(name);
67
+ if (old && old.value !== value)
68
+ throw reject();
69
+ controls.set(name, { value, writable: !disabled && attr(element, "readonly") === undefined });
70
+ }
71
+ const expected = {
72
+ sys_target: "sys_atf_step", sys_uniqueValue: input.stepId,
73
+ "sys_atf_step.sys_scope": input.scope, "sys_atf_step.test": input.testId,
74
+ "sys_atf_step.step_config": input.configId,
75
+ };
76
+ for (const [name, value] of Object.entries(expected))
77
+ if (controls.get(name)?.value !== value)
78
+ throw reject();
79
+ const token = controls.get("sysparm_ck")?.value;
80
+ if (!token || token.length > 1024 || /[\r\n]/.test(token))
81
+ throw reject();
82
+ const fields = new URLSearchParams({ sys_target: "sys_atf_step", sys_uniqueValue: input.stepId, sys_action: "sysverb_update", sysparm_ck: token });
83
+ // Existing step identity is verified above; do not replay other writable fields.
84
+ for (const [name, value] of Object.entries(input.inputs)) {
85
+ const control = `sys_atf_step.inputs.var__m_atf_input_variable_${input.configId}.${name}`;
86
+ if (!controls.get(control)?.writable)
87
+ throw reject();
88
+ if (exports.ATF_STEP_REFERENCE.test(value)) {
89
+ for (const prefix of ["sys_mapping.", "sys_mapping_display.", "sys_mapping.original."]) {
90
+ if (!controls.get(prefix + control)?.writable)
91
+ throw reject();
92
+ }
93
+ fields.set(control, "");
94
+ fields.set("sys_mapping." + control, value);
95
+ fields.set("sys_mapping_display." + control, value);
96
+ fields.set("sys_mapping.original." + control, controls.get("sys_mapping.original." + control).value);
97
+ }
98
+ else
99
+ fields.set(control, value);
100
+ }
101
+ return fields;
102
+ }
103
+ /** Cookies live only for one form load/save pair and never leave the exact origin. */
104
+ function atfFormCookies(headers) {
105
+ const cookies = headers.getSetCookie().map(header => header.split(";", 1)[0]);
106
+ if (cookies.length > 30 || cookies.join(";").length > 16384 || cookies.some(cookie => !/^[!#$%&'*+.^_`|~a-zA-Z0-9-]+=[^\x00-\x20\x7f;]*$/.test(cookie)))
107
+ throw reject();
108
+ return cookies.join("; ");
109
+ }
110
+ //# sourceMappingURL=atf-form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atf-form.js","sourceRoot":"","sources":["../src/atf-form.ts"],"names":[],"mappings":";;;AA2BA,wCAkDC;AAED,wCAIC;AAnFD,2EAA2E;AAC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AAO,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,kDAAkD,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAAE,MAAM,MAAM,EAAE,CAAC;IACxK,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * ATF execution grant carried on the resolved effective policy, and the
3
+ * classified denial a tool raises from its access resolver when the profile
4
+ * withholds that grant.
5
+ *
6
+ * Running an ATF suite executes its steps on the instance, and a step can
7
+ * change any table the test touches. No table-only plan can describe that
8
+ * side effect, so execution is its own opt-in: omission denies it.
9
+ *
10
+ * @module atf-policy
11
+ */
12
+ import type { ResolvedEffectivePolicyReference } from "./execution-context.js";
13
+ /** The ATF slice an EffectivePolicyProvider may state. */
14
+ export interface AtfExecutionPolicyInput {
15
+ readonly execute?: boolean;
16
+ readonly allowScriptSteps?: boolean;
17
+ }
18
+ /** Normalized, frozen ATF grants on a resolved policy. */
19
+ export interface AtfExecutionPolicy {
20
+ readonly execute: boolean;
21
+ readonly allowScriptSteps: boolean;
22
+ }
23
+ export declare const DENY_ALL_ATF_EXECUTION: AtfExecutionPolicy;
24
+ /**
25
+ * Normalize a provider-supplied ATF policy. Each property is read once, and
26
+ * anything other than an explicit boolean `true` leaves the grant off. A
27
+ * non-boolean value is a provider defect, so it fails context creation.
28
+ */
29
+ export declare function createAtfExecutionPolicy(candidate: AtfExecutionPolicyInput | undefined): AtfExecutionPolicy;
30
+ export type AtfPolicyFailureReason = "execution_not_enabled" | "script_steps_not_enabled";
31
+ export declare class AtfPolicyError extends Error {
32
+ readonly reason: AtfPolicyFailureReason;
33
+ constructor(reason: AtfPolicyFailureReason);
34
+ }
35
+ export declare function isAtfPolicyError(error: unknown): error is AtfPolicyError;
36
+ /**
37
+ * Fixed operator guidance. It names the configuration key that grants the
38
+ * operation, and keeps the "denied by policy" phrase other denials share.
39
+ */
40
+ export declare function atfPolicyDenialMessage(_error: AtfPolicyError, tool?: string): string;
41
+ /**
42
+ * Call from a module's resolveAccess before returning its plan, so a profile
43
+ * without the grant is rejected before any configuration or client exists.
44
+ */
45
+ export declare function requireAtfExecution(policy: Pick<ResolvedEffectivePolicyReference, "atf">): void;
46
+ //# sourceMappingURL=atf-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atf-policy.d.ts","sourceRoot":"","sources":["../src/atf-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAE/E,0DAA0D;AAC1D,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,0DAA0D;AAC1D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAED,eAAO,MAAM,sBAAsB,EAAE,kBAGnC,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,uBAAuB,GAAG,SAAS,GAC7C,kBAAkB,CAiBpB;AAED,MAAM,MAAM,sBAAsB,GAAG,uBAAuB,GAAG,0BAA0B,CAAC;AAI1F,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;gBAE5B,MAAM,EAAE,sBAAsB;CAO3C;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAMxE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,cAAc,EACtB,IAAI,CAAC,EAAE,MAAM,GACZ,MAAM,CAWR;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,IAAI,CAAC,gCAAgC,EAAE,KAAK,CAAC,GACpD,IAAI,CAIN"}