|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import test from "node:test"; |
| 3 | + |
| 4 | +import { personaSubmitBlock } from "./personaSubmitBlock.ts"; |
| 5 | + |
| 6 | +/** A fully valid, submittable form: personaSubmitBlock returns null. */ |
| 7 | +function submittable(overrides = {}) { |
| 8 | + return { |
| 9 | + isPending: false, |
| 10 | + isAvatarUploadPending: false, |
| 11 | + displayNameEmpty: false, |
| 12 | + isCreateMode: true, |
| 13 | + runtimeChosen: true, |
| 14 | + runtimeAvailable: true, |
| 15 | + createBackendBlocked: false, |
| 16 | + allowlistEmpty: false, |
| 17 | + aiConfigurationMode: "defaults", |
| 18 | + localModeSatisfied: true, |
| 19 | + localModeMissingFields: [], |
| 20 | + localModeMissingEnvKeys: [], |
| 21 | + customAiPairSatisfied: true, |
| 22 | + runtimeNeedsProviderSelection: true, |
| 23 | + customProviderEmpty: false, |
| 24 | + customModelEmpty: false, |
| 25 | + ...overrides, |
| 26 | + }; |
| 27 | +} |
| 28 | + |
| 29 | +test("a valid form has no disabled reason", () => { |
| 30 | + assert.equal(personaSubmitBlock(submittable()), null); |
| 31 | +}); |
| 32 | + |
| 33 | +test("missing name is reported first", () => { |
| 34 | + assert.equal( |
| 35 | + personaSubmitBlock(submittable({ displayNameEmpty: true })), |
| 36 | + "Enter a name for this agent.", |
| 37 | + ); |
| 38 | +}); |
| 39 | + |
| 40 | +test("Buzz Agent + Use AI defaults with no global provider/model names the fix", () => { |
| 41 | + const reason = personaSubmitBlock( |
| 42 | + submittable({ |
| 43 | + aiConfigurationMode: "defaults", |
| 44 | + localModeSatisfied: false, |
| 45 | + localModeMissingFields: ["provider", "model"], |
| 46 | + }), |
| 47 | + ); |
| 48 | + assert.match(reason, /global AI defaults are incomplete/); |
| 49 | + assert.match(reason, /a provider and a model/); |
| 50 | + assert.match(reason, /Settings → AI defaults/); |
| 51 | +}); |
| 52 | + |
| 53 | +test("incomplete defaults also names missing credential keys", () => { |
| 54 | + const reason = personaSubmitBlock( |
| 55 | + submittable({ |
| 56 | + localModeSatisfied: false, |
| 57 | + localModeMissingFields: [], |
| 58 | + localModeMissingEnvKeys: ["ANTHROPIC_API_KEY"], |
| 59 | + }), |
| 60 | + ); |
| 61 | + assert.match(reason, /a value for ANTHROPIC_API_KEY/); |
| 62 | +}); |
| 63 | + |
| 64 | +test("the reason disappears once the blocking input is corrected", () => { |
| 65 | + const blocked = submittable({ |
| 66 | + localModeSatisfied: false, |
| 67 | + localModeMissingFields: ["provider", "model"], |
| 68 | + }); |
| 69 | + assert.notEqual(personaSubmitBlock(blocked), null); |
| 70 | + // Correct the blocking input: defaults now resolve. |
| 71 | + const corrected = { |
| 72 | + ...blocked, |
| 73 | + localModeSatisfied: true, |
| 74 | + localModeMissingFields: [], |
| 75 | + }; |
| 76 | + assert.equal(personaSubmitBlock(corrected), null); |
| 77 | +}); |
| 78 | + |
| 79 | +test("create mode requires a chosen, available runtime", () => { |
| 80 | + assert.equal( |
| 81 | + personaSubmitBlock(submittable({ runtimeChosen: false })), |
| 82 | + "Choose where this agent runs.", |
| 83 | + ); |
| 84 | + assert.equal( |
| 85 | + personaSubmitBlock(submittable({ runtimeAvailable: false })), |
| 86 | + "The selected runtime isn't available on this machine.", |
| 87 | + ); |
| 88 | +}); |
| 89 | + |
| 90 | +test("runtime gates do not apply in edit mode", () => { |
| 91 | + assert.equal( |
| 92 | + personaSubmitBlock( |
| 93 | + submittable({ isCreateMode: false, runtimeChosen: false }), |
| 94 | + ), |
| 95 | + null, |
| 96 | + ); |
| 97 | +}); |
| 98 | + |
| 99 | +test("empty allowlist is reported (create and edit)", () => { |
| 100 | + const reason = personaSubmitBlock( |
| 101 | + submittable({ isCreateMode: false, allowlistEmpty: true }), |
| 102 | + ); |
| 103 | + assert.match(reason, /allowed sender/); |
| 104 | +}); |
| 105 | + |
| 106 | +test("Customize with an empty pair but satisfied global fallback points at the pair", () => { |
| 107 | + const reason = personaSubmitBlock( |
| 108 | + submittable({ |
| 109 | + aiConfigurationMode: "custom", |
| 110 | + localModeSatisfied: true, |
| 111 | + customAiPairSatisfied: false, |
| 112 | + customProviderEmpty: true, |
| 113 | + customModelEmpty: true, |
| 114 | + }), |
| 115 | + ); |
| 116 | + assert.match(reason, /Select a provider and a model/); |
| 117 | + assert.match(reason, /Use AI defaults/); |
| 118 | +}); |
| 119 | + |
| 120 | +test("Customize on Codex/Claude asks only for a model, never a provider", () => { |
| 121 | + const reason = personaSubmitBlock( |
| 122 | + submittable({ |
| 123 | + aiConfigurationMode: "custom", |
| 124 | + customAiPairSatisfied: false, |
| 125 | + runtimeNeedsProviderSelection: false, |
| 126 | + customProviderEmpty: true, |
| 127 | + customModelEmpty: true, |
| 128 | + }), |
| 129 | + ); |
| 130 | + assert.match(reason, /Select a model/); |
| 131 | + assert.doesNotMatch(reason, /provider/); |
| 132 | +}); |
| 133 | + |
| 134 | +test("precedence: a missing name outranks incomplete AI defaults", () => { |
| 135 | + assert.equal( |
| 136 | + personaSubmitBlock( |
| 137 | + submittable({ |
| 138 | + displayNameEmpty: true, |
| 139 | + localModeSatisfied: false, |
| 140 | + localModeMissingFields: ["provider", "model"], |
| 141 | + }), |
| 142 | + ), |
| 143 | + "Enter a name for this agent.", |
| 144 | + ); |
| 145 | +}); |
| 146 | + |
| 147 | +test("in-flight save/upload shows no reason (the button label communicates it)", () => { |
| 148 | + assert.equal( |
| 149 | + personaSubmitBlock( |
| 150 | + submittable({ isPending: true, displayNameEmpty: true }), |
| 151 | + ), |
| 152 | + null, |
| 153 | + ); |
| 154 | + assert.equal( |
| 155 | + personaSubmitBlock(submittable({ isAvatarUploadPending: true })), |
| 156 | + null, |
| 157 | + ); |
| 158 | +}); |
0 commit comments