Skip to content

Commit

Permalink
Merge pull request #4981 from Agoric/4941-lint-ava-tests
Browse files Browse the repository at this point in the history
test: lint Ava tests
  • Loading branch information
mhofman authored Aug 15, 2023
2 parents f2445bc + 7347734 commit 479a1a0
Show file tree
Hide file tree
Showing 41 changed files with 348 additions and 291 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ module.exports = {
}
: undefined,
plugins: ['@typescript-eslint', 'prettier'],
extends: ['@agoric'],
extends: ['@agoric', 'plugin:ava/recommended'],
rules: {
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/no-floating-promises': lintTypes ? 'warn' : 'off',
// so that floating-promises can be explicitly permitted with void operator
'no-void': ['error', { allowAsStatement: true }],

// We allow disabled tests in master
'ava/no-skip-test': 'off',
// Contrary to recommendation https://github.com/avajs/ava/blob/main/docs/recipes/typescript.md#typing-tcontext
'ava/use-test': 'off',

// The rule is “safe await separator" which implements the architectural
// goal of “clearly separate an async function's synchronous prelude from
// the part that runs in a future turn”. That is our architectural rule. It
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"ava": "^5.3.0",
"c8": "^7.13.0",
"conventional-changelog-conventionalcommits": "^4.6.0",
"eslint": "^8.44.0",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-jessie": "^0.0.6",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-github": "^4.8.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^46.4.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/test/test-bundle-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ test('bundle handler', async t => {
t.is(store.size, 2);
t.deepEqual(ids, ['b0-lockdown.sha', 'b0-supervisor.sha']);
// contents were fetched from bundleData
t.deepEqual(await handler.getBundle('b0-lockdown.sha'), 'lockdown');
t.deepEqual(await handler.getBundle('b0-supervisor.sha'), 'supervisor');
t.is(await handler.getBundle('b0-lockdown.sha'), 'lockdown');
t.is(await handler.getBundle('b0-supervisor.sha'), 'supervisor');

// subsequent queries should check hashes/ids but not re-read bundles
const ids2 = await handler.getCurrentBundleIDs();
Expand All @@ -67,7 +67,7 @@ test('bundle handler', async t => {

// getBundle is served from bundleStore, not elsewhere
store.set('b0-lockdown.sha', 'other');
t.deepEqual(await handler.getBundle('b0-lockdown.sha'), 'other');
t.is(await handler.getBundle('b0-lockdown.sha'), 'other');
});

test('bundle data', async t => {
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/test/test-inter-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ test('diagnostic for agd ENOENT', async t => {
});

await t.throwsAsync(cmd.parseAsync(argv), { instanceOf: CommanderError });
t.deepEqual(
t.is(
diag.join('').trim(),
"error: option '--from <address>' argument 'gov1' is invalid. ENOENT: is agd in your $PATH?",
);
t.deepEqual(out.join('').trim(), '');
t.is(out.join('').trim(), '');
});

test.todo('agd ENOENT clue outside normalizeAddress');
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/test/test-publish-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ test('publish bundle with fake HTTP server ok', async t => {
t.deepEqual(bundle, request);
res.end('{"ok": true}');
})().catch(error => {
t.fail(error);
t.fail(`${error.message}`);
});
});
t.teardown(
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/upgrading/test-upgrade-vats.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test('upgrade vat-board', async t => {
t.is(actualThing, thing, 'must get original value back');
});

test.skip('upgrade bootstrap vat', async t => {
test.failing('upgrade bootstrap vat', async t => {
const bundles = {
chain: {
sourceSpec: await importSpec('@agoric/vats/src/core/boot-chain.js'),
Expand Down
4 changes: 2 additions & 2 deletions packages/cosmic-swingset/test/test-export-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const makeBatchChainStorage = published => {
return { batchChainStorage, deleted };
};

test('exportStorage example', async t => {
test('exportStorage example', t => {
const exportStorageSubtrees = ['published.c.o'];
const expected = [
['published.c.o', 'top'],
Expand All @@ -82,7 +82,7 @@ test('exportStorage example', async t => {
t.deepEqual(actual, expected);
});

test('exportStorage clears crufty ToyUSD PSM', async t => {
test('exportStorage clears crufty ToyUSD PSM', t => {
const config = {
clearStorageSubtrees: ['published'],
exportStorageSubtrees: [
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@jessie.js/eslint-plugin": "^0.4.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"eslint": "^8.36.0",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-github": "^4.8.0",
"eslint-config-jessie": "^0.0.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable ava/assertion-arguments -- the standard diff is unreadable */
// eslint-disable-next-line import/no-extraneous-dependencies
import '@endo/init/debug.js';
import test from 'ava';
import { buildVatController, buildKernelBundles } from '@agoric/swingset-vat';
Expand Down
9 changes: 0 additions & 9 deletions packages/import-manager/test/unitTests/test-importsA.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,3 @@ test('import listIsEmpty (true)', t => {
const op = 'listIsEmpty';
t.truthy(importer[op]([]));
});

// TODO: This test throws because `lookupImport` does not exist. This
// test needs to be fixed.
test.skip('import not found', t => {
const importer = makeGoodImportManager();
t.throws(() => importer.lookupImport('emptyPixel'), {
message: /There is no entry for "c"./,
});
});
2 changes: 1 addition & 1 deletion packages/internal/test/test-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ test('far function callbacks', async t => {
t.is(await p2r, '19go');
});

test('bad callbacks', async t => {
test('bad callbacks', t => {
t.throws(
// @ts-expect-error deliberate: number is not assignable to function
() => cb.makeFunctionCallback(42),
Expand Down
4 changes: 2 additions & 2 deletions packages/internal/test/test-netstring.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test('encode', t => {
eq(emojiBuffer, expectedBuffer);
});

test('encode stream', async t => {
test('encode stream', t => {
const e = netstringEncoderStream();
const chunks = [];
e.on('data', data => chunks.push(data));
Expand Down Expand Up @@ -112,7 +112,7 @@ test('decode', t => {
bad('26:x', /size .* exceeds limit of 25/);
});

test('decode stream', async t => {
test('decode stream', t => {
const d = netstringDecoderStream();
function write(s) {
d.write(Buffer.from(s));
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/test/test-priority-senders.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test('normalization', async t => {
await manager.add('this,has,commas,', 'addr');

await writesSettled();
t.deepEqual(
t.is(
storage.data.get(`${HIGH_PRIORITY_SENDERS}.addr`),
'something_with_spaces,something_with_spaces_and___,this_has_commas_',
);
Expand Down
6 changes: 4 additions & 2 deletions packages/notifier/test/test-publish-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,16 @@ test('durable publish kit upgrade trauma (full-vat integration)', async t => {
const eachIterator2 = await run('messageVatObject', [
{ presence: eachIterable, methodName: Symbol.asyncIterator },
]);
// eslint-disable-next-line ava/prefer-async-await
const assertDisconnection = (p, label) => {
const expected = {
incarnationNumber: 0,
name: 'vatUpgraded',
upgradeMessage: 'vat upgraded',
};
return p.then(
(...args) => t.deepEqual(args, undefined, `${label} must be rejected`),
// @ts-expect-error Argument of type 'undefined' is not assignable to parameter of type 'any[]'.
(...args) => t.is(args, undefined, `${label} must be rejected`),
failure =>
t.deepEqual(failure, expected, `${label} must indicate disconnection`),
);
Expand Down Expand Up @@ -458,7 +460,7 @@ test('durable publish kit upgrade trauma (full-vat integration)', async t => {
// TODO: Find a way to test virtual object rehydration
// without the overhead of vats.
// https://github.com/Agoric/agoric-sdk/pull/6502#discussion_r1008492055
test.skip('durable publish kit upgrade trauma', async t => {
test.failing('durable publish kit upgrade trauma', async t => {
const baggage = makeBaggage();
const makeDurablePublishKit = prepareDurablePublishKit(
baggage,
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/test/test-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test.serial('home.localTimerService makeNotifier', async t => {
const notifier = E(localTimerService).makeNotifier(1n, 1n);
const update1 = await E(notifier).getUpdateSince();
const firstUpdate = update1.updateCount;
t.truthy(firstUpdate > 0);
t.true(firstUpdate > 0);
const update2 = await E(notifier).getUpdateSince(update1.updateCount);
t.truthy(BigInt(update2.updateCount) > BigInt(firstUpdate));

Expand Down
99 changes: 99 additions & 0 deletions packages/swing-store/test/exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Buffer } from 'buffer';
import { makeB0ID } from './util.js';

export const snapshotData = 'snapshot data';
// this snapHash was computed manually
export const snapHash =
'e7dee7266896538616b630a5da40a90e007726a383e005a9c9c5dd0c2daf9329';

/** @type {import('../src/bundleStore.js').Bundle} */
export const bundle0 = { moduleFormat: 'nestedEvaluate', source: '1+1' };
export const bundle0ID = makeB0ID(bundle0);

export function buildData() {
// build an export manually
const exportData = new Map();
const artifacts = new Map();

// shadow kvStore
exportData.set('kv.key1', 'value1');

// now add artifacts and metadata in pairs

artifacts.set(`bundle.${bundle0ID}`, JSON.stringify(bundle0));
exportData.set(`bundle.${bundle0ID}`, bundle0ID);

const sbase = { vatID: 'v1', hash: snapHash, inUse: 0 };
const tbase = { vatID: 'v1', startPos: 0, isCurrent: 0, incarnation: 1 };
const addTS = (key, obj) =>
exportData.set(key, JSON.stringify({ ...tbase, ...obj }));
const t0hash =
'5bee0f44eca02f23eab03703e84ed2647d5d117fed99e1c30a3b424b7f082ab9';
const t2hash =
'57152efdd7fdf75c03371d2b4f1088d5bf3eae7fe643babce527ff81df38998c';
const t5hash =
'1947001e78e01bd1e773feb22b4ffc530447373b9de9274d5d5fbda3f23dbf2b';
const t8hash =
'e6b42c6a3fb94285a93162f25a9fc0145fd4c5bb144917dc572c50ae2d02ee69';

addTS(`transcript.v1.0`, { incarnation: 0, endPos: 2, hash: t0hash });
artifacts.set(`transcript.v1.0.2`, 'start-worker\nshutdown-worker\n');

addTS(`transcript.v1.2`, { startPos: 2, endPos: 5, hash: t2hash });
artifacts.set(
`transcript.v1.2.5`,
'start-worker\ndelivery1\nsave-snapshot\n',
);
exportData.set(`snapshot.v1.4`, JSON.stringify({ ...sbase, snapPos: 4 }));
artifacts.set(`snapshot.v1.4`, snapshotData);

addTS(`transcript.v1.5`, { startPos: 5, endPos: 8, hash: t5hash });
artifacts.set(
'transcript.v1.5.8',
'load-snapshot\ndelivery2\nsave-snapshot\n',
);
exportData.set(
`snapshot.v1.7`,
JSON.stringify({ ...sbase, snapPos: 7, inUse: 1 }),
);
artifacts.set(`snapshot.v1.7`, snapshotData);

artifacts.set('transcript.v1.8.10', 'load-snapshot\ndelivery3\n');
exportData.set(`snapshot.v1.current`, 'snapshot.v1.7');
addTS(`transcript.v1.current`, {
startPos: 8,
endPos: 10,
isCurrent: 1,
hash: t8hash,
});

return { exportData, artifacts, t0hash, t2hash, t5hash, t8hash };
}

/**
* @param { Map<string, string | null> } exportData
* @param { Map<string, string> } artifacts
*/
export function makeExporter(exportData, artifacts) {
return {
async *getExportData() {
for (const [key, value] of exportData.entries()) {
/** @type { import('../src/exporter.js').KVPair } */
const pair = [key, value];
yield pair;
}
},
async *getArtifactNames() {
for (const name of artifacts.keys()) {
yield name;
}
},
async *getArtifact(name) {
const data = artifacts.get(name);
assert(data, `missing artifact ${name}`);
yield Buffer.from(data);
},
// eslint-disable-next-line no-empty-function
async close() {},
};
}
Loading

0 comments on commit 479a1a0

Please sign in to comment.