π OpenHands: AI-Driven Development
feat: send template provenance for versioned setup entries (#16458)
Hiep Leb1f0accae165
diff --git a/__tests__/manifests/automation-setup.test.ts b/__tests__/manifests/automation-setup.test.tsindex 0b8d5f9d0c..bce1e3781a 100644--- a/__tests__/manifests/automation-setup.test.ts+++ b/__tests__/manifests/automation-setup.test.ts@@ -291,6 +291,43 @@ describe("buildCreatePayload", () => {// Assertexpect(payload).toBeNull();});++ it("attaches template provenance when the entry carries a version", () => {+ // Arrange+ const entry = createSetupEntry({ version: "1.0.0" });+ const values = {+ repository: "octo/widgets",+ widgetName: "gadget",+ schedule: "*/5 * * * *",+ };++ // Act+ const payload = buildCreatePayload(entry, values);++ // Assert+ expect(payload?.template).toEqual({+ id: "widget-monitor",+ version: "1.0.0",+ config: values,+ });+ });++ it("sends the payload unchanged for an entry without a version", () => {+ // Arrange+ const entry = createSetupEntry();+ const values = {+ repository: "octo/widgets",+ widgetName: "gadget",+ schedule: "*/5 * * * *",+ };++ // Act+ const payload = buildCreatePayload(entry, values);++ // Assert+ expect(payload).not.toBeNull();+ expect(payload).not.toHaveProperty("template");+ });});describe("buildPreflightBody", () => {diff --git a/__tests__/manifests/manifest-validation.test.ts b/__tests__/manifests/manifest-validation.test.tsindex dc03d8948c..70a731c549 100644--- a/__tests__/manifests/manifest-validation.test.ts+++ b/__tests__/manifests/manifest-validation.test.ts@@ -23,7 +23,7 @@ function formWithField(describe("validateSetupEntry", () => {it("admits a well-formed manifest", () => {// Arrange- const entry = createSetupEntry();+ const entry = createSetupEntry({ version: "1.0.0" });// Actconst result = validateSetupEntry(entry);@@ -48,6 +48,23 @@ describe("validateSetupEntry", () => {expect(result).toEqual({ valid: true, errors: [] });});+ // A catalog may publish an entry ahead of its stable release. The version is+ // forwarded as provenance, not compared, so a pre-release or build suffix is+ // a version this host admits rather than a reason to drop the entry.+ it.each(["1.0.0-beta.1", "1.0.0+build.5", "2.1.0-rc.1+build.5"])(+ "admits the template version %s",+ (version) => {+ // Arrange+ const entry = createSetupEntry({ version });++ // Act+ const result = validateSetupEntry(entry);++ // Assert+ expect(result).toEqual({ valid: true, errors: [] });+ },+ );+// Each case is a separate invariant the host enforces on data authored in// another repository. A manifest that trips any of them must not render.it.each([@@ -69,6 +86,18 @@ describe("validateSetupEntry", () => {"markup inside a direct entry's fallback message",{ setup: createSetup({ message: "<img src=x onerror=alert(1)>" }) },],+ [+ // A direct entry may seed a fallback conversation, but the message stays+ // setup context only, so the cap still refuses a runaway one.+ "a fallback message that exceeds the setup-context cap",+ { setup: createSetup({ message: "x".repeat(2001) }) },+ ],+ [+ // The version is sent to the service as template provenance, so a+ // malformed one is refused rather than forwarded.+ "a template version that is not semver",+ { version: "v1" },+ ],[// The host reads one trigger kind to build the request, so a second one// would be silently dropped rather than refused.diff --git a/src/manifests/manifest-validation.ts b/src/manifests/manifest-validation.tsindex aaec4932e7..f926c4cc8a 100644--- a/src/manifests/manifest-validation.ts+++ b/src/manifests/manifest-validation.ts@@ -28,9 +28,14 @@ const FIELD_NAME_PATTERN = /^[a-z][A-Za-z0-9]*$/;const MARKUP_PATTERN = /<[A-Za-z/!]/;/*** A template version, declared as `version` by a prompt entry and as- * `setup.bundle.version` by a bundle one.+ * `setup.bundle.version` by a bundle one. Sent to the service as template+ * provenance, so it is checked at admission. Full semver, as the spec at+ * semver.org states it: a catalog entry published with a pre-release or build+ * suffix is still a version this host may forward, and refusing one would drop+ * the entry from the registry outright.*/-const TEMPLATE_VERSION_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/;+const TEMPLATE_VERSION_PATTERN =+ /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/;// The characters a command of plain words and paths is made of. No shell// metacharacters, which the service rejects anyway and a bundle has no reason// to need; where those words may point is `isPlainCommand`'s to say.