feat: add account run history module and logging functionality
- Implemented `background/account-run-history.js` to persist account run results (success, failure, stop) in `chrome.storage.local` and log to a text file when the local Hotmail helper is enabled. - Enhanced `background/auto-run-controller.js` and `background/message-router.js` to utilize the new account run record functionality. - Updated steps in `background/steps/fetch-login-code.js`, `background/steps/fetch-signup-code.js`, and `background/steps/oauth-login.js` to handle retries and logging appropriately. - Introduced tests for account run history and step retry limits to ensure functionality and reliability. - Modified documentation to reflect new features and changes in behavior for specific providers (e.g., 2925).
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
|
||||
test('background imports account run history module', () => {
|
||||
const source = fs.readFileSync('background.js', 'utf8');
|
||||
assert.match(source, /background\/account-run-history\.js/);
|
||||
});
|
||||
|
||||
test('account run history module exposes a factory', () => {
|
||||
const source = fs.readFileSync('background/account-run-history.js', 'utf8');
|
||||
const globalScope = {};
|
||||
|
||||
const api = new Function('self', `${source}; return self.MultiPageBackgroundAccountRunHistory;`)(globalScope);
|
||||
|
||||
assert.equal(typeof api?.createAccountRunHistoryHelpers, 'function');
|
||||
});
|
||||
|
||||
test('account run history helper normalizes records and persists without helper upload when local helper is disabled', async () => {
|
||||
const source = fs.readFileSync('background/account-run-history.js', 'utf8');
|
||||
const globalScope = {};
|
||||
const api = new Function('self', `${source}; return self.MultiPageBackgroundAccountRunHistory;`)(globalScope);
|
||||
|
||||
let storedHistory = [{ email: 'old@example.com', password: 'old-pass', status: 'success', recordedAt: '2026-04-17T00:00:00.000Z' }];
|
||||
let fetchCalled = false;
|
||||
global.fetch = async () => {
|
||||
fetchCalled = true;
|
||||
throw new Error('should not call fetch');
|
||||
};
|
||||
|
||||
const helpers = api.createAccountRunHistoryHelpers({
|
||||
ACCOUNT_RUN_HISTORY_STORAGE_KEY: 'accountRunHistory',
|
||||
addLog: async () => {},
|
||||
buildHotmailLocalEndpoint: (baseUrl, path) => `${baseUrl}${path}`,
|
||||
chrome: {
|
||||
storage: {
|
||||
local: {
|
||||
get: async () => ({ accountRunHistory: storedHistory }),
|
||||
set: async (payload) => {
|
||||
storedHistory = payload.accountRunHistory;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
getErrorMessage: (error) => error?.message || String(error || ''),
|
||||
getState: async () => ({
|
||||
email: ' latest@example.com ',
|
||||
password: ' secret ',
|
||||
hotmailServiceMode: 'remote',
|
||||
hotmailLocalBaseUrl: '',
|
||||
}),
|
||||
HOTMAIL_SERVICE_MODE_LOCAL: 'local',
|
||||
normalizeHotmailLocalBaseUrl: (value) => String(value || '').trim(),
|
||||
});
|
||||
|
||||
const record = helpers.buildAccountRunHistoryRecord(
|
||||
{ email: ' latest@example.com ', password: ' secret ' },
|
||||
' FAILED ',
|
||||
' reason '
|
||||
);
|
||||
assert.deepStrictEqual(record, {
|
||||
email: 'latest@example.com',
|
||||
password: 'secret',
|
||||
status: 'failed',
|
||||
recordedAt: record.recordedAt,
|
||||
reason: 'reason',
|
||||
});
|
||||
|
||||
const appended = await helpers.appendAccountRunRecord('failed', null, 'boom');
|
||||
assert.equal(appended.email, 'latest@example.com');
|
||||
assert.equal(appended.status, 'failed');
|
||||
assert.equal(storedHistory.length, 2);
|
||||
assert.equal(storedHistory[1].reason, 'boom');
|
||||
assert.equal(fetchCalled, false);
|
||||
assert.equal(helpers.shouldAppendAccountRunTextFile({ hotmailServiceMode: 'remote', hotmailLocalBaseUrl: 'http://127.0.0.1:17373' }), false);
|
||||
});
|
||||
Reference in New Issue
Block a user