Cursor/f6a8ad17 (#1014)

This commit is contained in:
James Read 2026-05-11 10:15:12 +01:00 committed by GitHub
commit 19797c0784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 43 deletions

View File

@ -27,11 +27,11 @@
{{ choice.title || choice.value }} {{ choice.title || choice.value }}
</option> </option>
</select> </select>
<component v-else :is="getInputComponent(arg)" :id="arg.name" :name="arg.name" <component v-else :is="getInputComponent(arg)" :id="arg.name" :name="arg.name"
:value="(arg.type === 'checkbox' || arg.type === 'confirmation') ? undefined : getArgumentValue(arg)" :value="(arg.type === 'checkbox' || arg.type === 'confirmation') ? undefined : getArgumentValue(arg)"
:checked="(arg.type === 'checkbox' || arg.type === 'confirmation') ? getArgumentValue(arg) : undefined" :checked="(arg.type === 'checkbox' || arg.type === 'confirmation') ? getArgumentValue(arg) : undefined"
:list="(arg.suggestions || getBrowserSuggestions(arg).length > 0) ? `${arg.name}-choices` : undefined" :list="(arg.suggestions || getBrowserSuggestions(arg).length > 0) ? `${arg.name}-choices` : undefined"
:type="getInputComponent(arg) !== 'select' ? getInputType(arg) : undefined" :type="getInputComponent(arg) !== 'select' ? getInputType(arg) : undefined"
:rows="arg.type === 'raw_string_multiline' ? 5 : undefined" :rows="arg.type === 'raw_string_multiline' ? 5 : undefined"
:step="arg.type === 'datetime' ? 1 : undefined" :pattern="getPattern(arg)" :step="arg.type === 'datetime' ? 1 : undefined" :pattern="getPattern(arg)"
@ -174,7 +174,7 @@ function getInputType(arg) {
return 'checkbox' return 'checkbox'
} }
if (arg.type === 'ascii_identifier' || arg.type === 'ascii') { if (arg.type === 'ascii_identifier' || arg.type === 'ascii' || arg.type === 'ascii_sentence') {
return 'text' return 'text'
} }
@ -252,7 +252,7 @@ async function validateArgument(arg, value) {
// Get the input element to set custom validity // Get the input element to set custom validity
const inputElement = document.getElementById(arg.name) const inputElement = document.getElementById(arg.name)
if (validation.valid) { if (validation.valid) {
delete formErrors.value[arg.name] delete formErrors.value[arg.name]
// Clear custom validity message // Clear custom validity message
@ -322,7 +322,7 @@ function getBrowserSuggestions(arg) {
if (!arg.suggestionsBrowserKey) { if (!arg.suggestionsBrowserKey) {
return [] return []
} }
try { try {
const stored = localStorage.getItem(`olivetin-suggestions-${arg.suggestionsBrowserKey}`) const stored = localStorage.getItem(`olivetin-suggestions-${arg.suggestionsBrowserKey}`)
if (stored) { if (stored) {
@ -332,7 +332,7 @@ function getBrowserSuggestions(arg) {
} catch (err) { } catch (err) {
console.warn('Failed to load browser suggestions:', err) console.warn('Failed to load browser suggestions:', err)
} }
return [] return []
} }
@ -340,21 +340,21 @@ function saveBrowserSuggestions() {
for (const arg of actionArguments.value) { for (const arg of actionArguments.value) {
if (arg.suggestionsBrowserKey) { if (arg.suggestionsBrowserKey) {
const value = argValues.value[arg.name] const value = argValues.value[arg.name]
// Only save non-empty values for non-checkbox/confirmation/password types // Only save non-empty values for non-checkbox/confirmation/password types
if (value && value !== '' && arg.type !== 'checkbox' && arg.type !== 'confirmation' && arg.type !== 'password') { if (value && value !== '' && arg.type !== 'checkbox' && arg.type !== 'confirmation' && arg.type !== 'password') {
try { try {
const key = `olivetin-suggestions-${arg.suggestionsBrowserKey}` const key = `olivetin-suggestions-${arg.suggestionsBrowserKey}`
const stored = localStorage.getItem(key) const stored = localStorage.getItem(key)
let suggestions = [] let suggestions = []
if (stored) { if (stored) {
suggestions = JSON.parse(stored) suggestions = JSON.parse(stored)
if (!Array.isArray(suggestions)) { if (!Array.isArray(suggestions)) {
suggestions = [] suggestions = []
} }
} }
// Add value if not already present // Add value if not already present
if (!suggestions.includes(value)) { if (!suggestions.includes(value)) {
suggestions.unshift(value) // Add to beginning suggestions.unshift(value) // Add to beginning
@ -390,11 +390,13 @@ async function startAction(actionArgs) {
} }
async function handleSubmit(event) { async function handleSubmit(event) {
event.preventDefault()
// Set custom validity for required fields // Set custom validity for required fields
for (const arg of actionArguments.value) { for (const arg of actionArguments.value) {
const value = argValues.value[arg.name] const value = argValues.value[arg.name]
const inputElement = document.getElementById(arg.name) const inputElement = document.getElementById(arg.name)
if (arg.required && (!value || value === '')) { if (arg.required && (!value || value === '')) {
formErrors.value[arg.name] = 'This field is required' formErrors.value[arg.name] = 'This field is required'
// Set custom validity for required field validation // Set custom validity for required field validation
@ -410,14 +412,12 @@ async function handleSubmit(event) {
return return
} }
event.preventDefault()
const argvs = getArgumentValues() const argvs = getArgumentValues()
console.log('argument form has elements that passed validation') console.log('argument form has elements that passed validation')
// Save values to localStorage for arguments with suggestionsBrowserKey // Save values to localStorage for arguments with suggestionsBrowserKey
saveBrowserSuggestions() saveBrowserSuggestions()
try { try {
const response = await startAction(argvs) const response = await startAction(argvs)
if (popupOnStart.value && popupOnStart.value.includes('execution-dialog')) { if (popupOnStart.value && popupOnStart.value.includes('execution-dialog')) {
@ -496,4 +496,4 @@ form {
display: inline; display: inline;
font-weight: normal; font-weight: normal;
} }
</style> </style>

View File

@ -13,8 +13,10 @@ actions:
- name: testInput - name: testInput
title: Test Input title: Test Input
description: "This input uses suggestionsBrowserKey" description: "This input uses suggestionsBrowserKey"
type: ascii_sentence
suggestionsBrowserKey: test-suggestions-key suggestionsBrowserKey: test-suggestions-key
- name: testInput2 - name: testInput2
title: Test Input 2 title: Test Input 2
description: "This input shares the same suggestionsBrowserKey" description: "This input shares the same suggestionsBrowserKey"
type: ascii_sentence
suggestionsBrowserKey: test-suggestions-key suggestionsBrowserKey: test-suggestions-key

View File

@ -5,7 +5,6 @@ import {
getRootAndWait, getRootAndWait,
getActionButton, getActionButton,
takeScreenshotOnFailure, takeScreenshotOnFailure,
getTerminalBuffer,
} from '../../lib/elements.js' } from '../../lib/elements.js'
async function openArgumentForm() { async function openArgumentForm() {
@ -45,7 +44,7 @@ async function waitForLogsPage() {
const url = await webdriver.getCurrentUrl() const url = await webdriver.getCurrentUrl()
return url.includes('/logs/') && !url.endsWith('/logs') return url.includes('/logs/') && !url.endsWith('/logs')
}), }),
5000 15000
) )
} }
@ -115,14 +114,16 @@ describe('config: suggestionsBrowserKey', function () {
it('Submitting form saves value to localStorage', async function () { it('Submitting form saves value to localStorage', async function () {
this.timeout(15000) this.timeout(15000)
// Clear localStorage first // Clear localStorage first
await clearLocalStorage() await clearLocalStorage()
await openArgumentForm() await openArgumentForm()
const input = await getTestInput() const input = await getTestInput()
const testValue = 'test-value-123' // Use default argument type "ascii" (alphanumeric only) so tests pass when
// config does not set a looser type (e.g. CI merge base without type lines).
const testValue = 'testvalue123'
await input.clear() await input.clear()
await input.sendKeys(testValue) await input.sendKeys(testValue)
@ -133,7 +134,7 @@ describe('config: suggestionsBrowserKey', function () {
// Verify value was saved to localStorage // Verify value was saved to localStorage
const stored = await getLocalStorageItem('olivetin-suggestions-test-suggestions-key') const stored = await getLocalStorageItem('olivetin-suggestions-test-suggestions-key')
expect(stored).to.not.be.null expect(stored).to.not.be.null
const suggestions = JSON.parse(stored) const suggestions = JSON.parse(stored)
expect(suggestions).to.be.an('array') expect(suggestions).to.be.an('array')
expect(suggestions).to.include(testValue) expect(suggestions).to.include(testValue)
@ -141,9 +142,9 @@ describe('config: suggestionsBrowserKey', function () {
it('Previously saved values appear in datalist', async function () { it('Previously saved values appear in datalist', async function () {
this.timeout(15000) this.timeout(15000)
// First, save a value to localStorage // First, save a value to localStorage
const testValue = 'saved-suggestion-456' const testValue = 'savedsuggestion456'
await webdriver.executeScript(` await webdriver.executeScript(`
const key = 'olivetin-suggestions-test-suggestions-key'; const key = 'olivetin-suggestions-test-suggestions-key';
localStorage.setItem(key, JSON.stringify(['${testValue}'])); localStorage.setItem(key, JSON.stringify(['${testValue}']));
@ -173,7 +174,7 @@ describe('config: suggestionsBrowserKey', function () {
it('Multiple submissions accumulate suggestions', async function () { it('Multiple submissions accumulate suggestions', async function () {
this.timeout(20000) this.timeout(20000)
// Clear localStorage first // Clear localStorage first
await clearLocalStorage() await clearLocalStorage()
@ -181,7 +182,7 @@ describe('config: suggestionsBrowserKey', function () {
await openArgumentForm() await openArgumentForm()
const input1 = await getTestInput() const input1 = await getTestInput()
await input1.clear() await input1.clear()
await input1.sendKeys('first-value') await input1.sendKeys('firstvalue')
await submitForm() await submitForm()
await waitForLogsPage() await waitForLogsPage()
await waitForExecutionComplete() await waitForExecutionComplete()
@ -190,7 +191,7 @@ describe('config: suggestionsBrowserKey', function () {
await openArgumentForm() await openArgumentForm()
const input2 = await getTestInput() const input2 = await getTestInput()
await input2.clear() await input2.clear()
await input2.sendKeys('second-value') await input2.sendKeys('secondvalue')
await submitForm() await submitForm()
await waitForLogsPage() await waitForLogsPage()
await waitForExecutionComplete() await waitForExecutionComplete()
@ -198,17 +199,17 @@ describe('config: suggestionsBrowserKey', function () {
// Verify both values are in localStorage // Verify both values are in localStorage
const stored = await getLocalStorageItem('olivetin-suggestions-test-suggestions-key') const stored = await getLocalStorageItem('olivetin-suggestions-test-suggestions-key')
expect(stored).to.not.be.null expect(stored).to.not.be.null
const suggestions = JSON.parse(stored) const suggestions = JSON.parse(stored)
expect(suggestions).to.be.an('array') expect(suggestions).to.be.an('array')
expect(suggestions).to.include('first-value') expect(suggestions).to.include('firstvalue')
expect(suggestions).to.include('second-value') expect(suggestions).to.include('secondvalue')
expect(suggestions[0]).to.equal('second-value') // Most recent should be first expect(suggestions[0]).to.equal('secondvalue') // Most recent should be first
}) })
it('Empty values are not saved to localStorage', async function () { it('Empty values are not saved to localStorage', async function () {
this.timeout(15000) this.timeout(15000)
// Clear localStorage first // Clear localStorage first
await clearLocalStorage() await clearLocalStorage()
@ -235,7 +236,7 @@ describe('config: suggestionsBrowserKey', function () {
it('Suggestions are shared across inputs with the same suggestionsBrowserKey', async function () { it('Suggestions are shared across inputs with the same suggestionsBrowserKey', async function () {
this.timeout(20000) this.timeout(20000)
// Clear localStorage first // Clear localStorage first
await clearLocalStorage() await clearLocalStorage()
@ -243,14 +244,14 @@ describe('config: suggestionsBrowserKey', function () {
await openArgumentForm() await openArgumentForm()
const input1 = await getTestInput() const input1 = await getTestInput()
await input1.clear() await input1.clear()
await input1.sendKeys('shared-value-from-input1') await input1.sendKeys('sharedfrominput1')
await submitForm() await submitForm()
await waitForLogsPage() await waitForLogsPage()
await waitForExecutionComplete() await waitForExecutionComplete()
// Open the form again and verify the value appears in both datalists // Open the form again and verify the value appears in both datalists
await openArgumentForm() await openArgumentForm()
// Check first input's datalist // Check first input's datalist
const datalist1 = await webdriver.findElement(By.id('testInput-choices')) const datalist1 = await webdriver.findElement(By.id('testInput-choices'))
expect(datalist1).to.not.be.null expect(datalist1).to.not.be.null
@ -258,7 +259,7 @@ describe('config: suggestionsBrowserKey', function () {
let foundInInput1 = false let foundInInput1 = false
for (const option of options1) { for (const option of options1) {
const value = await option.getAttribute('value') const value = await option.getAttribute('value')
if (value === 'shared-value-from-input1') { if (value === 'sharedfrominput1') {
foundInInput1 = true foundInInput1 = true
break break
} }
@ -272,7 +273,7 @@ describe('config: suggestionsBrowserKey', function () {
let foundInInput2 = false let foundInInput2 = false
for (const option of options2) { for (const option of options2) {
const value = await option.getAttribute('value') const value = await option.getAttribute('value')
if (value === 'shared-value-from-input1') { if (value === 'sharedfrominput1') {
foundInInput2 = true foundInInput2 = true
break break
} }
@ -282,24 +283,24 @@ describe('config: suggestionsBrowserKey', function () {
// Now submit a value using the second input // Now submit a value using the second input
const input2 = await getTestInput2() const input2 = await getTestInput2()
await input2.clear() await input2.clear()
await input2.sendKeys('shared-value-from-input2') await input2.sendKeys('sharedfrominput2')
await submitForm() await submitForm()
await waitForLogsPage() await waitForLogsPage()
await waitForExecutionComplete() await waitForExecutionComplete()
// Verify both values appear in both datalists // Verify both values appear in both datalists
await openArgumentForm() await openArgumentForm()
// Check that both values are in the first input's datalist // Check that both values are in the first input's datalist
const options1After = await getDatalistOptions('testInput') const options1After = await getDatalistOptions('testInput')
let foundValue1 = false let foundValue1 = false
let foundValue2 = false let foundValue2 = false
for (const option of options1After) { for (const option of options1After) {
const value = await option.getAttribute('value') const value = await option.getAttribute('value')
if (value === 'shared-value-from-input1') { if (value === 'sharedfrominput1') {
foundValue1 = true foundValue1 = true
} }
if (value === 'shared-value-from-input2') { if (value === 'sharedfrominput2') {
foundValue2 = true foundValue2 = true
} }
} }
@ -312,10 +313,10 @@ describe('config: suggestionsBrowserKey', function () {
foundValue2 = false foundValue2 = false
for (const option of options2After) { for (const option of options2After) {
const value = await option.getAttribute('value') const value = await option.getAttribute('value')
if (value === 'shared-value-from-input1') { if (value === 'sharedfrominput1') {
foundValue1 = true foundValue1 = true
} }
if (value === 'shared-value-from-input2') { if (value === 'sharedfrominput2') {
foundValue2 = true foundValue2 = true
} }
} }