Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing improvements #5774

Merged
merged 2 commits into from
Jul 19, 2022
Merged

testing improvements #5774

merged 2 commits into from
Jul 19, 2022

Conversation

turadg
Copy link
Member

@turadg turadg commented Jul 15, 2022

Description

#5766 ran into a problem with test.todo not being available in ses-ava. 524e7de adds it. (fyi @erights )

I also got fed up with this noise in test output. 295c8aa removes it.
Screen Shot 2022-07-12 at 7 55 13 AM

Security Considerations

none

Documentation Considerations

--

Testing Considerations

Better

@turadg turadg requested a review from kriskowal July 15, 2022 22:43
@turadg turadg marked this pull request as draft July 15, 2022 22:57
patches/@endo+ses-ava+0.2.27.patch Outdated Show resolved Hide resolved
* propagating into `rawTest`.
*
- * @param {TesterInterface} avaTest
+ * @param {import('ava').TestInterface} avaTest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we confident that our emulation satisfies the entire ava interface now? Or, is this a convenient fiction that improves the debug experience?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right we don't. That's why this still returns TestInterface. But the avaTest param is indeed from Ava.

Marking this as Draft because my refactor broke some case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confident now that it satisfies because it passes through whatever it doesn't override. I typed the param as generic so that it wraps whatever version of Ava was passed in.

@turadg
Copy link
Member Author

turadg commented Jul 15, 2022

@kriskowal why do we have a whitelist of what to allow through? shouldn't it be an "override" list that's passed over after copying everything? IIUC "ses-ava" package is to provide SES-happy console output, not for actual security of the test run.

@kriskowal
Copy link
Member

kriskowal commented Jul 16, 2022

@kriskowal why do we have a whitelist of what to allow through? shouldn't it be an "override" list that's passed over after copying everything? IIUC "ses-ava" package is to provide SES-happy console output, not for actual security of the test run.

I should in this case defer to @erights, but this may have been born of abundance-of-caution or force-of-security-habit and eligible for a rethink.

@turadg turadg force-pushed the ta/testing-improvements branch from 524e7de to 5a3fc6a Compare July 16, 2022 15:38
@turadg turadg requested review from erights and kriskowal July 16, 2022 15:40
@turadg
Copy link
Member Author

turadg commented Jul 16, 2022

I looked into the open issues for ses-ava and these would be solved by having the "override" list instead of an "allow" list:
endojs/endo#645
endojs/endo#647

But I don't understand why this fence was put here! @erights ?

I also don't know the symptoms of not using ses-ava at all. Do they persist in Ava 4?

@turadg
Copy link
Member Author

turadg commented Jul 16, 2022

Also, since the prepare-test-env is mutating the env, why not mutate Ava test itself? Status quo is we have these prepare-test-env-ava.js files that have both side-effects AND exports. Because they have side-effects they have to go before other imports. But then when they use relative paths our lint rules complain that it should be lower, so we have to suppress:

/* eslint-disable import/order */
import { test } from '../tools/prepare-test-env-ava.js';

There are 36 of those.

How about this instead?

import '../tools/prepare-test-env-ava.js';

import test from 'ava';

packages/solo/test/test-home.js Show resolved Hide resolved
packages/zoe/src/contractFacet/zcfZygote.js Show resolved Hide resolved
patches/@endo+ses-ava+0.2.27.patch Show resolved Hide resolved
patches/@endo+ses-ava+0.2.27.patch Outdated Show resolved Hide resolved
patches/@endo+ses-ava+0.2.27.patch Show resolved Hide resolved
patches/@endo+ses-ava+0.2.27.patch Show resolved Hide resolved
patches/@endo+ses-ava+0.2.27.patch Show resolved Hide resolved
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I see @kriskowal already approved, I'm changing my comments to Request changes as an interlock, even though it is still not R4R

@erights
Copy link
Member

erights commented Jul 16, 2022

@kriskowal why do we have a whitelist of what to allow through? shouldn't it be an "override" list that's passed over after copying everything? IIUC "ses-ava" package is to provide SES-happy console output, not for actual security of the test run.

Yeah, it isn't for security. It is to keep track of which methods we've examined to determine whether to augment them or not. Perhaps we should have two whitelists: The ones we know we want to augment, and the ones we know we don't. It is an interesting policy choice what to do with the remainder: Do we preserve their existing behavior (as your code does) until we decide, or do we omit them until we decide?

@erights
Copy link
Member

erights commented Jul 16, 2022

Also, since the prepare-test-env is mutating the env, why not mutate Ava test itself? Status quo is we have these prepare-test-env-ava.js files that have both side-effects AND exports. Because they have side-effects they have to go before other imports. But then when they use relative paths our lint rules complain that it should be lower, so we have to suppress:

/* eslint-disable import/order */
import { test } from '../tools/prepare-test-env-ava.js';

There are 36 of those.

How about this instead?

import '../tools/prepare-test-env-ava.js';

import test from 'ava';

Whether or not we mutate test in place, shouldn't we still prefer the former to the latter because it is shorter (less big of a deal) and bundles related issues together so it is less of a refactoring hazard?

Also, wouldn't the first line of the latter still need to come first? If it does and still uses the '../tools/...' form you show above, wouldn't it still need the eslint-disable?

@erights
Copy link
Member

erights commented Jul 16, 2022

I also don't know the symptoms of not using ses-ava at all. Do they persist in Ava 4?

The consequence is that the seeming console output is neither from the real console nor from the replacement that lockdown installs instead. Thus it lacks the crucial diagnostic info that's especially important when we're iterating the development of our test.

@turadg
Copy link
Member Author

turadg commented Jul 17, 2022

Yeah, it isn't for security.

Ok good. So the purpose of the "ses-ava" package isn't for security, just to accommodate SES's console handling when testing with Ava.

It is to keep track of which methods we've examined to determine whether to augment them or not. Perhaps we should have two whitelists: The ones we know we want to augment, and the ones we know we don't. It is an interesting policy choice what to do with the remainder: Do we preserve their existing behavior (as your code does) until we decide, or do we omit them until we decide?

I can't think of any reason to omit any part of the Ava test framework. The user shouldn't have to lose functionality because of SES's console requirements. (The lack of .todo was a surprise which broke my build and my focus.) For runtime, one list suffices: modify these methods so work better in SES. The rest should pass through. If there is any value in keeping track of "we looked into this one and it doesn't need augmentation", that's a documentation concern. A list like that in a comment above the override list would be fine by me, though I don't see the value in that. I expect whenever there's a problem that it'll get reported and then belong on the override list. If something is known to need overriding and that's not working yet, that could go into the override list, commented out with an explanation (and ideally a link to a ticket).

@turadg
Copy link
Member Author

turadg commented Jul 17, 2022

/* eslint-disable import/order */
import { test } from '../tools/prepare-test-env-ava.js';

How about this instead?

import '../tools/prepare-test-env-ava.js';

import test from 'ava';

Whether or not we mutate test in place, shouldn't we still prefer the former to the latter because it is shorter (less big of a deal) and bundles related issues together so it is less of a refactoring hazard?

I think those are both offset by the value of consistent Ava tests, regardless of whether SES env is prepared. What's "related" is "prepare env" and when you prepare env or not, it should not change the ergonomics of writing a test. By bundling shims which have side effects with exports of symbols to use, I argue that this is more of a refactoring hazard.

Also, wouldn't the first line of the latter still need to come first? If it does and still uses the '../tools/...' form you show above, wouldn't it still need the eslint-disable?

Good question. The way the rule works, if you import without a symbol it's assumed to have side effects so it's exempt from ordering rules.

Note that this PR isn't requesting the change. I asked to understand why it's like this in the first place and to see if we can agree on the proposed way. (I've since seen in PR history of Endo that it used to be the way I'm proposing.) If we do, I'll file a ticket to do that after MN-1.

But my immediate goal with this PR is to make SES-Ava conform to the Ava API.

@turadg turadg force-pushed the ta/testing-improvements branch from cbcf9e5 to ba710c0 Compare July 17, 2022 15:16
@turadg turadg requested a review from erights July 17, 2022 15:16
@turadg turadg marked this pull request as ready for review July 17, 2022 15:16
@erights
Copy link
Member

erights commented Jul 18, 2022

If there is any value in keeping track of "we looked into this one and it doesn't need augmentation", that's a documentation concern.

I am ok with this, and with your other points above that I did not comment on.

Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving in a rush as explained at #5774 (comment)

@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Jul 18, 2022
@turadg turadg force-pushed the ta/testing-improvements branch from e9a7d03 to 200921a Compare July 18, 2022 22:21
@turadg turadg force-pushed the ta/testing-improvements branch from 200921a to 3b5fd6c Compare July 18, 2022 23:39
@mergify mergify bot merged commit 41c6a3f into master Jul 19, 2022
@mergify mergify bot deleted the ta/testing-improvements branch July 19, 2022 00:30
gibson042 added a commit to endojs/endo that referenced this pull request Jan 25, 2023
gibson042 added a commit to endojs/endo that referenced this pull request Jan 27, 2023
gibson042 added a commit to endojs/endo that referenced this pull request Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants