Skip to content

Commit 337b7b2

Browse files
authored
recipe2plan 2/n: Validate Handles, Tests (#4834)
* creating structure of ts r2p script * Created fast CLI rapper for r2p script * WIP figuring out ways to resolve a recipe * fix sp * Passing lint, still WIP * Build macros for recipe2plan work * Lightweight iteration on recipe2plan, stubbed out tests * Revised method to find corresponding create handles * Added type info * Added method to get all handles to manifest + get all handles by Id * fix: no flatMap * - currently, fails since it cannot find associated stores for handles. * uncleaned, but working recipe resolution * Cleaned up for r2p, pt 1 * stubbed out second test (short, short) * Squashed commit of the following: commit 62dcc57 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:38:14 2020 -0800 Fixed test, added TODO * updates to test, can't get two to fail * Squashed commit of the following: commit bede8d9 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:52:02 2020 -0800 Fixed build rule, simplified runtime commit 62dcc57 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:38:14 2020 -0800 Fixed test, added TODO * can't get test to fail... hmm... * Squashed commit of the following: commit f6df54a Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 15:44:32 2020 -0800 tools/sigh lint commit bede8d9 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:52:02 2020 -0800 Fixed build rule, simplified runtime commit 62dcc57 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:38:14 2020 -0800 Fixed test, added TODO * adjusting recipe copying to include triggers * Revert "adjusting recipe copying to include triggers" This reverts commit 9bc3734 * four tests complete * Added test, fixed minor async issue * Squashed commit of the following: commit 4b05a28 Merge: f4c1d26 99000c2 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:18:14 2020 -0800 Merge branch 'r2p' of github.com:alxrsngrtn/arcs into r2p commit f4c1d26 Merge: 140111f 5c6310d Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:14:35 2020 -0800 Merge branch 'master' of github.com:PolymerLabs/arcs into r2p Fixed lint errors commit 99000c2 Merge: 140111f 5c6310d Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:14:35 2020 -0800 Merge branch 'master' of github.com:PolymerLabs/arcs into r2p Fixed lint errors commit 140111f Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:08:12 2020 -0800 Removed flatMap, added TODOs and link to GH issue commit 5c6310d Author: jblebrun <[email protected]> Date: Tue Mar 3 11:02:34 2020 -0800 Simplify service test pattern (#4817) * Make a simple test lifecycle registry, instead of creating empty testactivity * Remove use of `runBlockingTest`: according to Kotlin/kotlinx.coroutines#1222, if the test results in coroutines being finished on other threads, it's possible to receive "This job has not yet completed" exceptions, even though the jobs were properly terminated. Since we don't need the delay-skipping properties of `runBlockingTest`, I think it's OK to use `runBlocking`. commit 472bc84 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 10:27:56 2020 -0800 Improved build rules commit ca1ebf8 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 10:17:13 2020 -0800 Impl suggestsions for r2p commit b5578ea Author: Jason Feinstein <[email protected]> Date: Tue Mar 3 09:54:17 2020 -0800 Add tests for dereferencing references to the HandleManagerTest(s) (#4816) * Add dereferencing tests to the android handle manager test. * Add dereferencing tests to core HandleManager. commit a695797 Author: Jason Feinstein <[email protected]> Date: Mon Mar 2 18:14:07 2020 -0800 Create RawEntityDereferencerTest, storage Reference-> CrdtEntity.Reference (#4812) * Create RawEntityDereferencerTest, make storage Reference implement CrdtEntity.Reference. Also: Create ParcelableReference. * Add dep. Also, apparently read/writeBoolean is Q-only. * Just write null if there is no version map. * Just write null if there is no version map. commit ba7a107 Author: Gogul Balakrishnan <[email protected]> Date: Mon Mar 2 17:51:35 2020 -0800 Add a decoder for PrimitiveTypeProto and an option to disable android constraints in BUILD. (#4793) commit f6df54a Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 15:44:32 2020 -0800 tools/sigh lint commit bede8d9 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:52:02 2020 -0800 Fixed build rule, simplified runtime commit 62dcc57 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:38:14 2020 -0800 Fixed test, added TODO * fix ineq * existing tests passing * Updating invalid type test * Squashed commit of the following: commit b3d92d0 Author: Alex Rosengarten <[email protected]> Date: Wed Mar 4 12:17:17 2020 -0800 updated test name commit ba7884b Author: Alex Rosengarten <[email protected]> Date: Wed Mar 4 12:16:09 2020 -0800 nested unit tests commit ef36fdf Author: Alex Rosengarten <[email protected]> Date: Wed Mar 4 12:15:00 2020 -0800 renamed to tryResolve commit 5703f02 Author: Alex Rosengarten <[email protected]> Date: Wed Mar 4 12:07:18 2020 -0800 rm generator commit 658cb1a Author: Alex Rosengarten <[email protected]> Date: Wed Mar 4 12:01:54 2020 -0800 implemented more review suggestions commit 0056ee3 Merge: cae89c3 0f0f82a Author: Alex Rosengarten <[email protected]> Date: Wed Mar 4 11:54:23 2020 -0800 Merge branch 'master' of github.com:PolymerLabs/arcs into r2p commit 0f0f82a Author: Maria Mandlis <[email protected]> Date: Wed Mar 4 09:33:29 2020 -0800 add queryable capability (#4794) commit d032c75 Author: Maria Mandlis <[email protected]> Date: Wed Mar 4 09:23:07 2020 -0800 add creatimeTimestamp to entities (kt) (#4823) commit 30267fc Author: jblebrun <[email protected]> Date: Wed Mar 4 09:09:39 2020 -0800 Remove some unused deps (#4831) commit c519181 Author: Cameron Silvestrini <[email protected]> Date: Wed Mar 4 17:14:07 2020 +1100 Increase size of DatabaseImplTest to medium (#4827) * Increase size of DatabaseImplTest to medium Was a bit flaky. * Check flakiness * Revert presubmit tweak commit fa621c6 Author: jblebrun <[email protected]> Date: Tue Mar 3 22:05:07 2020 -0800 Fix a race condition when setting up `ServiceStore` message channel (#4826) This seems to be the cause of the flakiness in `AndroidAllocatorTest` and `AndroidHandleManagerTest` (#4781) commit 78bf4f0 Author: Gogul Balakrishnan <[email protected]> Date: Tue Mar 3 18:00:49 2020 -0800 Utility to convert type proto to field type (if possible). (#4814) commit cae89c3 Merge: 0360752 e587539 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 15:50:34 2020 -0800 Merge branch 'master' of github.com:PolymerLabs/arcs into r2p commit e587539 Author: jblebrun <[email protected]> Date: Tue Mar 3 15:07:16 2020 -0800 Apply simplified test pattern tests in `arcs.android.host` (#4821) As in 5c6310d commit 1af1aac Author: Joshua Pratt <[email protected]> Date: Wed Mar 4 09:48:15 2020 +1100 Multinomials (#4804) * multinomial * added tests * making constant readable again * reindent * added multivariate rearrangement tests * updated comment * pr comments: Co-authored-by: Ragav Sachdeva <[email protected]> commit 0360752 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:42:31 2020 -0800 fix, bad comparison op commit 4b05a28 Merge: f4c1d26 99000c2 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:18:14 2020 -0800 Merge branch 'r2p' of github.com:alxrsngrtn/arcs into r2p commit f4c1d26 Merge: 140111f 5c6310d Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:14:35 2020 -0800 Merge branch 'master' of github.com:PolymerLabs/arcs into r2p Fixed lint errors commit 99000c2 Merge: 140111f 5c6310d Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:14:35 2020 -0800 Merge branch 'master' of github.com:PolymerLabs/arcs into r2p Fixed lint errors commit 140111f Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 11:08:12 2020 -0800 Removed flatMap, added TODOs and link to GH issue commit 5c6310d Author: jblebrun <[email protected]> Date: Tue Mar 3 11:02:34 2020 -0800 Simplify service test pattern (#4817) * Make a simple test lifecycle registry, instead of creating empty testactivity * Remove use of `runBlockingTest`: according to Kotlin/kotlinx.coroutines#1222, if the test results in coroutines being finished on other threads, it's possible to receive "This job has not yet completed" exceptions, even though the jobs were properly terminated. Since we don't need the delay-skipping properties of `runBlockingTest`, I think it's OK to use `runBlocking`. commit 472bc84 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 10:27:56 2020 -0800 Improved build rules commit ca1ebf8 Author: Alex Rosengarten <[email protected]> Date: Tue Mar 3 10:17:13 2020 -0800 Impl suggestsions for r2p commit b5578ea Author: Jason Feinstein <[email protected]> Date: Tue Mar 3 09:54:17 2020 -0800 Add tests for dereferencing references to the HandleManagerTest(s) (#4816) * Add dereferencing tests to the android handle manager test. * Add dereferencing tests to core HandleManager. commit a695797 Author: Jason Feinstein <[email protected]> Date: Mon Mar 2 18:14:07 2020 -0800 Create RawEntityDereferencerTest, storage Reference-> CrdtEntity.Reference (#4812) * Create RawEntityDereferencerTest, make storage Reference implement CrdtEntity.Reference. Also: Create ParcelableReference. * Add dep. Also, apparently read/writeBoolean is Q-only. * Just write null if there is no version map. * Just write null if there is no version map. commit ba7a107 Author: Gogul Balakrishnan <[email protected]> Date: Mon Mar 2 17:51:35 2020 -0800 Add a decoder for PrimitiveTypeProto and an option to disable android constraints in BUILD. (#4793) commit f6df54a Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 15:44:32 2020 -0800 tools/sigh lint commit bede8d9 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:52:02 2020 -0800 Fixed build rule, simplified runtime commit 62dcc57 Author: Alex Rosengarten <[email protected]> Date: Mon Mar 2 14:38:14 2020 -0800 Fixed test, added TODO * fixed nested tests * rewording, reorganizing * assert more ergonomic
1 parent 298fdcc commit 337b7b2

File tree

2 files changed

+123
-21
lines changed

2 files changed

+123
-21
lines changed

src/tools/storage-key-recipe-resolver.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ export class StorageKeyRecipeResolver {
3232
/**
3333
* Produces resolved recipes with storage keys.
3434
*
35-
* TODO(alxr): Apply to long-running recipes appropriately.
35+
* TODO(#4818) Add passes to assign storage keys.
3636
* @throws Error if recipe fails to resolve on first or second pass.
3737
* @yields Resolved recipes with storage keys
3838
*/
3939
async resolve(): Promise<Recipe[]> {
4040
const recipes = [];
4141
for (const recipe of this.runtime.context.allRecipes) {
42+
this.validateHandles(recipe);
4243
const arc = this.runtime.newArc(this.getArcId(recipe), ramDiskStorageKeyPrefixForTest());
4344
const opts = {errors: new Map<Recipe | RecipeComponent, string>()};
4445
const resolved = await this.tryResolve(recipe, arc, opts);
@@ -63,7 +64,8 @@ export class StorageKeyRecipeResolver {
6364
*/
6465
async tryResolve(recipe: Recipe, arc: Arc, opts?: IsValidOptions): Promise<Recipe | null> {
6566
const normalized = recipe.clone();
66-
normalized.normalize();
67+
const successful = normalized.normalize(opts);
68+
if (!successful) return null;
6769
if (normalized.isResolved()) return normalized;
6870

6971
return await (new RecipeResolver(arc).resolve(recipe, opts));
@@ -97,14 +99,14 @@ export class StorageKeyRecipeResolver {
9799
}
98100

99101
/**
100-
* TODO(#4818) method to match `map` and `copy` fated handles with storage keys from `create` handles.
102+
* Checks that handles are existent, disambiguous, and initiated by a long-running arc.
101103
*
102-
* @throws when a mapped handle is associated with too many stores (ambiguous mapping).
103-
* @throws when a mapped handle isn't associated with any store (no matches found).
104-
* @throws when handle is mapped to a handle from an ephemeral recipe.
104+
* @throws when a map or copy handle is associated with too many stores (ambiguous mapping).
105+
* @throws when a map or copy handle isn't associated with any store (no matches found).
106+
* @throws when a map or copy handle is associated with a handle from an ephemeral recipe.
105107
* @param recipe long-running or ephemeral recipe
106108
*/
107-
matchKeysToHandles(recipe: Recipe) {
109+
validateHandles(recipe: Recipe) {
108110
recipe.handles
109111
.filter(h => h.fate === 'map' || h.fate === 'copy')
110112
.forEach(handle => {
@@ -121,8 +123,6 @@ export class StorageKeyRecipeResolver {
121123
if (!match.recipe.isLongRunning) {
122124
throw Error(`Handle ${handle.localName} mapped to ephemeral handle ${match.localName}.`);
123125
}
124-
125-
handle.storageKey = match.storageKey;
126126
});
127127
}
128128
}

src/tools/tests/storage-key-recipe-resolver-test.ts

+114-12
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
import {Manifest} from '../../runtime/manifest.js';
1212
import {assert} from '../../platform/chai-node.js';
1313
import {StorageKeyRecipeResolver} from '../storage-key-recipe-resolver.js';
14+
import {assertThrowsAsync} from '../../testing/test-util.js';
1415

1516
describe('recipe2plan', () => {
1617
describe('storage-key-recipe-resolver', () => {
17-
it('Resolves mapping a handle from a long running arc into another long running arc', async () => {
18+
it('resolves mapping a handle from a long running arc into another long running arc', async () => {
1819
const manifest = await Manifest.parse(`\
1920
particle Reader
2021
data: reads Thing {name: Text}
@@ -28,33 +29,134 @@ describe('recipe2plan', () => {
2829
2930
@trigger
3031
launch startup
31-
arcId myArcId
32+
arcId writeArcId
3233
recipe WritingRecipe
3334
thing: create persistent 'my-handle-id'
3435
Writer
3536
data: writes thing
3637
3738
@trigger
3839
launch startup
39-
arcId otherArcId
40+
arcId readArcId
4041
recipe ReadingRecipe
4142
data: map 'my-handle-id'
4243
Reader
4344
data: reads data`);
4445

4546
const resolver = new StorageKeyRecipeResolver(manifest);
46-
for (const it of (await resolver.resolve())) {
47+
for (const it of (await resolver.resolve())) {
4748
assert.isTrue(it.isResolved());
4849
}
4950
});
51+
it('fails to resolve mapping a handle from a short running arc into another short running arc', async () => {
52+
const manifest = await Manifest.parse(`\
53+
particle Reader
54+
data: reads Thing {name: Text}
55+
56+
particle Writer
57+
data: writes Thing {name: Text}
58+
59+
recipe WritingRecipe
60+
thing: create persistent 'my-handle-id'
61+
Writer
62+
data: writes thing
63+
64+
recipe ReadingRecipe
65+
data: map 'my-handle-id'
66+
Reader
67+
data: reads data`);
68+
69+
const resolver = new StorageKeyRecipeResolver(manifest);
70+
await assertThrowsAsync(async () => await resolver.resolve(), Error, 'Handle data mapped to ephemeral handle thing.');
71+
});
72+
it('fails to resolve mapping a handle from a short running arc into a long running arc', async () => {
73+
const manifest = await Manifest.parse(`\
74+
particle Reader
75+
data: reads Thing {name: Text}
76+
77+
particle Writer
78+
data: writes Thing {name: Text}
79+
80+
recipe WritingRecipe
81+
thing: create persistent 'my-handle-id'
82+
Writer
83+
data: writes thing
84+
85+
@trigger
86+
launch startup
87+
arcId readArcId
88+
recipe ReadingRecipe
89+
data: map 'my-handle-id'
90+
Reader
91+
data: reads data`);
92+
93+
const resolver = new StorageKeyRecipeResolver(manifest);
94+
await assertThrowsAsync(async () => await resolver.resolve(), Error, 'Handle data mapped to ephemeral handle thing.');
95+
});
96+
it('resolves mapping a handle from a long running arc into a short running arc', async () => {
97+
const manifest = await Manifest.parse(`\
98+
particle Reader
99+
data: reads Thing {name: Text}
100+
101+
particle Writer
102+
data: writes Thing {name: Text}
103+
104+
@trigger
105+
launch startup
106+
arcId writeArcId
107+
recipe WritingRecipe
108+
thing: create persistent 'my-handle-id'
109+
Writer
110+
data: writes thing
111+
112+
recipe ReadingRecipe
113+
data: map 'my-handle-id'
114+
Reader
115+
data: reads data`);
116+
117+
const resolver = new StorageKeyRecipeResolver(manifest);
118+
for (const it of await resolver.resolve()) {
119+
assert.isTrue(it.isResolved());
120+
}
121+
});
122+
it('Invalid Type: If Reader reads {name: Text, age: Number} it is not valid', async () => {
123+
const manifest = await Manifest.parse(`\
124+
particle Reader
125+
data: reads Thing {name: Text, age: Number}
126+
127+
particle Writer
128+
data: writes Thing {name: Text}
129+
130+
@trigger
131+
launch startup
132+
arcId writeArcId
133+
recipe WritingRecipe
134+
thing: create persistent 'my-handle-id'
135+
Writer
136+
data: writes thing
137+
138+
@trigger
139+
launch startup
140+
arcId readArcId
141+
recipe ReadingRecipe
142+
data: map 'my-handle-id'
143+
Reader
144+
data: reads data`);
145+
146+
const resolver = new StorageKeyRecipeResolver(manifest);
147+
// TODO: specify the correct error to be thrown
148+
await assertThrowsAsync(resolver.resolve);
149+
});
50150
// TODO(alxr): Flush out outlined unit tests
51-
it.skip('Short + Short: If WritingRecipe is short lived, it is not valid', () => {});
52-
it.skip('Short + Long: If WritingRecipe is short lived and Reading is long lived, it is not valid', () => {});
53-
it.skip('Invalid Type: If Reader reads {name: Text, age: Number} it is not valid', () => {});
54-
it.skip('No arc id: If arcId of WritingRecipe is not there, it is not valid', () => {});
55-
it.skip('No handleId: If id of handle in WritingRecipe is not provided, it is not valid', () => {});
56-
it.skip('Ambiguous handle: If there are 2 WritingRecipes creating the same handle, it is not valid', () => {});
57-
it.skip('Ambiguous handle + tag disambiguation: If there are 2 WritingRecipes creating the same handle but with different tags and mapping uses one of the tags, it is valid', () => {});
58-
it.skip('No Handle: If there is no writing handle, it is not valid', () => {});
151+
it.skip('No arc id: If arcId of WritingRecipe is not there, it is not valid', () => {
152+
});
153+
it.skip('No handleId: If id of handle in WritingRecipe is not provided, it is not valid', () => {
154+
});
155+
it.skip('Ambiguous handle: If there are 2 WritingRecipes creating the same handle, it is not valid', () => {
156+
});
157+
it.skip('Ambiguous handle + tag disambiguation: If there are 2 WritingRecipes creating the same handle but with different tags and mapping uses one of the tags, it is valid', () => {
158+
});
159+
it.skip('No Handle: If there is no writing handle, it is not valid', () => {
160+
});
59161
});
60162
});

0 commit comments

Comments
 (0)