Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(agent-vault): word the sheet's reference errors like the API's

Scott Wilson6dc6e4627f67
diff --git a/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts b/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts
index e7567bef03..5304b358e4 100644
--- a/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts
+++ b/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts
@@ -64,7 +64,8 @@ const CONTROL_CHARS_MESSAGE =
// Double braces wrap a variable reference, and neither a prefix nor a placeholder takes one.
const hasDoubleBraces = (text: string) => text.includes("{{") || text.includes("}}");
-const PREFIX_BRACES_MESSAGE = "A prefix can't contain {{ or }}.";
+const PREFIX_BRACES_MESSAGE =
+ "A prefix can't contain {{ or }}. Put a variable reference in the value instead.";
// Set by the proxy on every request, so naming one here would either be dropped or corrupt the request.
const RESERVED_HEADER_NAMES = new Set([
@@ -281,7 +282,7 @@ export const buildServiceSchema = (service?: TAgentVaultService | null, variable
} else if (hasDoubleBraces(substitution.placeholder)) {
at(
"placeholder",
- "A placeholder can't contain {{ or }}. Those wrap a variable reference."
+ "A placeholder can't contain {{ or }}. Double braces are reserved for variable references."
);
} else if (seenPlaceholders.has(substitution.placeholder)) {
at("placeholder", "This placeholder is listed twice.");
diff --git a/frontend/src/helpers/agentVaultVariables.test.ts b/frontend/src/helpers/agentVaultVariables.test.ts
index 95a81532e0..d0343471c7 100644
--- a/frontend/src/helpers/agentVaultVariables.test.ts
+++ b/frontend/src/helpers/agentVaultVariables.test.ts
@@ -1,6 +1,10 @@
import { describe, expect, it } from "vitest";
-import { findVariableReferenceAtCaret } from "./agentVaultVariables";
+import {
+ findVariableReferenceAtCaret,
+ VARIABLE_KEY_MESSAGE,
+ variableReferenceError
+} from "./agentVaultVariables";
describe("findVariableReferenceAtCaret", () => {
it("reads the whole key of an unfinished reference when the caret moves back into it", () => {
@@ -34,3 +38,18 @@ describe("findVariableReferenceAtCaret", () => {
expect(findVariableReferenceAtCaret("plain", 3)).toBeNull();
});
});
+
+describe("variableReferenceError", () => {
+ it.each(["{{1TOKEN}}", "{{_TOKEN}}", "{{ TOKEN }}", "{{API-KEY}}", "{{github_token}}", "{{}}"])(
+ "gives the whole key rule for %s",
+ (text) => {
+ expect(variableReferenceError(text)).toBe(
+ `"${text}" isn't a valid variable reference. ${VARIABLE_KEY_MESSAGE}`
+ );
+ }
+ );
+
+ it("passes a well-formed reference to a key the bundle has", () => {
+ expect(variableReferenceError("Bearer {{GITHUB_TOKEN}}", new Set(["GITHUB_TOKEN"]))).toBeNull();
+ });
+});
diff --git a/frontend/src/helpers/agentVaultVariables.ts b/frontend/src/helpers/agentVaultVariables.ts
index 95ab3690ae..fc26822edb 100644
--- a/frontend/src/helpers/agentVaultVariables.ts
+++ b/frontend/src/helpers/agentVaultVariables.ts
@@ -5,7 +5,7 @@ export const MAX_REFERENCES_PER_FIELD = 3;
export const VARIABLE_KEY_RE = /^[A-Z][A-Z0-9_]*$/;
export const VARIABLE_KEY_MESSAGE =
- "Start with a letter, then use upper case letters, numbers and underscores, like GITHUB_TOKEN.";
+ "A variable key starts with a letter and uses only upper case letters, numbers and underscores, like GITHUB_TOKEN.";
// Every {{...}} counts as a reference, so a malformed one is caught on save instead of being sent to a
// real host as literal text.
@@ -80,12 +80,12 @@ export const variableReferenceError = (text: string, keys?: ReadonlySet<string>)
const refs = findVariableReferences(text);
if (refs.length > MAX_REFERENCES_PER_FIELD) {
- return `Use at most ${MAX_REFERENCES_PER_FIELD} variable references in one value. A repeated reference counts each time.`;
+ return `A value can use at most ${MAX_REFERENCES_PER_FIELD} variable references, and a reference that repeats counts each time. Combine some into one variable to use fewer.`;
}
const malformed = refs.find((ref) => !VARIABLE_KEY_RE.test(ref));
if (malformed !== undefined) {
- return `"${toVariableReference(malformed)}" is not a variable. Keys are upper case, like GITHUB_TOKEN.`;
+ return `"${toVariableReference(malformed)}" isn't a valid variable reference. ${VARIABLE_KEY_MESSAGE}`;
}
const missing = keys ? refs.find((ref) => !keys.has(ref)) : undefined;