Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ test-cli: build-go
@echo "--- CLI Tests ---"
@$(CURDIR)/clicker/bin/vibium$(EXE) daemon stop 2>/dev/null || true
@$(CURDIR)/clicker/bin/vibium$(EXE) daemon start --headless
$(TIMEOUT_CMD) node --test $(TEST_FLAGS) --test-concurrency=1 tests/cli/navigation.test.js tests/cli/elements.test.js tests/cli/actionability.test.js tests/cli/page-reading.test.js tests/cli/input-tools.test.js tests/cli/pages.test.js tests/cli/page-context.test.js tests/cli/find-refs.test.js
$(TIMEOUT_CMD) node --test $(TEST_FLAGS) --test-concurrency=1 tests/cli/navigation.test.js tests/cli/elements.test.js tests/cli/actionability.test.js tests/cli/page-reading.test.js tests/cli/input-tools.test.js tests/cli/pages.test.js tests/cli/page-context.test.js tests/cli/find-refs.test.js tests/cli/storage.test.js
@$(CURDIR)/clicker/bin/vibium$(EXE) daemon stop 2>/dev/null || true
@echo "--- CLI Process Tests (sequential) ---"
$(TIMEOUT_CMD) node --test $(TEST_FLAGS) --test-concurrency=1 tests/cli/process.test.js
Expand Down
12 changes: 11 additions & 1 deletion clicker/internal/agent/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3949,11 +3949,21 @@ func (h *Handlers) browserStorageState(args map[string]interface{}) (*ToolsCallR
})()
})`

storageResult, err := h.client.Evaluate("", script)
storageEvalResult, err := h.client.Evaluate("", script)
if err != nil {
return nil, fmt.Errorf("failed to get storage: %w", err)
}

storageStr, ok := storageEvalResult.(string)
if !ok {
return nil, fmt.Errorf("unexpected storage result type: %T", storageEvalResult)
}

var storageResult interface{}
if err := json.Unmarshal([]byte(storageStr), &storageResult); err != nil {
return nil, fmt.Errorf("failed to parse storage data: %w", err)
}

// Build combined state
state := map[string]interface{}{
"cookies": cookies,
Expand Down
90 changes: 90 additions & 0 deletions tests/cli/storage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* CLI Tests: Storage export/restore
* Verifies `vibium storage` / `vibium storage restore` round-trip
* localStorage and sessionStorage correctly.
*/

const { test, describe, before, after } = require('node:test');
const assert = require('node:assert');
const { execSync, spawn } = require('node:child_process');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { VIBIUM } = require('../helpers');

let serverProcess, baseURL, statePath;

before(async () => {
serverProcess = spawn('node', [path.join(__dirname, '../helpers/test-server.js')], {
stdio: ['pipe', 'pipe', 'pipe'],
});
baseURL = await new Promise((resolve) => {
serverProcess.stdout.once('data', (data) => {
resolve(data.toString().trim());
});
});
execSync(`${VIBIUM} go ${baseURL}/`, { encoding: 'utf-8', timeout: 30000 });
statePath = path.join(os.tmpdir(), `vibium-storage-test-${Date.now()}.json`);
});

after(() => {
if (statePath && fs.existsSync(statePath)) fs.unlinkSync(statePath);
if (serverProcess) serverProcess.kill();
});

describe('CLI: storage export/restore', () => {
test('export produces a real nested JSON object, not a double-encoded string', () => {
execSync(`${VIBIUM} eval "localStorage.setItem('user', 'user_vibium')"`, {
encoding: 'utf-8',
timeout: 30000,
});
execSync(`${VIBIUM} eval "sessionStorage.setItem('session_id', 'session_vibium')"`, {
encoding: 'utf-8',
timeout: 30000,
});

execSync(`${VIBIUM} storage -o ${statePath}`, { encoding: 'utf-8', timeout: 30000 });
const state = JSON.parse(fs.readFileSync(statePath, 'utf-8'));

// Guard
assert.strictEqual(
typeof state.storage,
'object',
'"storage" must be a nested object, not a double-encoded string'
);
assert.strictEqual(state.storage.localStorage.user, 'user_vibium');
assert.strictEqual(state.storage.sessionStorage.session_id, 'session_vibium');
});

test('restore round-trip repopulates localStorage and sessionStorage', () => {
execSync(`${VIBIUM} eval "localStorage.clear(); sessionStorage.clear();"`, {
encoding: 'utf-8',
timeout: 30000,
});

// Sanity check: confirm storage is actually empty before restoring
const before = execSync(`${VIBIUM} eval "localStorage.getItem('user')"`, {
encoding: 'utf-8',
timeout: 30000,
}).trim();
assert.strictEqual(before, 'null');

const result = execSync(`${VIBIUM} storage restore ${statePath}`, {
encoding: 'utf-8',
timeout: 30000,
});
assert.match(result, /restored/i, 'Should confirm storage was restored');

const user = execSync(`${VIBIUM} eval "localStorage.getItem('user')"`, {
encoding: 'utf-8',
timeout: 30000,
}).trim();
const sessionId = execSync(`${VIBIUM} eval "sessionStorage.getItem('session_id')"`, {
encoding: 'utf-8',
timeout: 30000,
}).trim();

assert.strictEqual(user, 'user_vibium', 'localStorage should be restored');
assert.strictEqual(sessionId, 'session_vibium', 'sessionStorage should be restored');
});
});
Loading