Skip to content

Commit bec206b

Browse files
committed
test(cli): Add demo section tests, excluding familiar-chat
1 parent 9bcb8c7 commit bec206b

7 files changed

+259
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @import {TestRoutine} from '../types */
2+
3+
/** @type {TestRoutine} */
4+
export const section = async (execa, testLine) => {
5+
// If a runlet returns a promise for some value, it will print that value before exiting gracefully.
6+
await testLine(execa`endo run runlet.js a b c`, {
7+
stdout: "Hello, World! [ 'a', 'b', 'c' ]\n42",
8+
});
9+
};
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/** @import {Context, TestRoutine} from '../types' */
2+
3+
/** @type {TestRoutine} */
4+
export const section = async (execa, testLine) => {
5+
// We can create an instance of the counter and give it a name.
6+
await testLine(execa`endo make counter.js --name counter`, {
7+
stdout: 'Object [Alleged: Counter] {}',
8+
});
9+
10+
// Then, we can send messages to the counter and see their responses...
11+
await testLine(execa`endo eval E(counter).incr() counter`, {
12+
stdout: '1',
13+
});
14+
await testLine(execa`endo eval E(counter).incr() counter`, {
15+
stdout: '2',
16+
});
17+
await testLine(execa`endo eval E(counter).incr() counter`, {
18+
stdout: '3',
19+
});
20+
21+
// Aside: in all the above cases, we use counter both as the property name...
22+
await testLine(execa`endo eval E(c).incr() c:counter`, {
23+
stdout: '4',
24+
});
25+
26+
// Endo preserves the commands that led to the creation of the counter value...
27+
await testLine(execa`endo restart`);
28+
await testLine(execa`endo eval E(counter).incr() counter`, {
29+
stdout: '1',
30+
});
31+
await testLine(execa`endo eval E(counter).incr() counter`, {
32+
stdout: '2',
33+
});
34+
await testLine(execa`endo eval E(counter).incr() counter`, {
35+
stdout: '3',
36+
});
37+
38+
// Aside, since Eventual Send, the machinery under the E operator...
39+
await testLine(execa`endo spawn greeter`);
40+
await testLine(
41+
execa`endo eval --worker greeter '${'Hello, World!'}' --name greeting`,
42+
{
43+
stdout: 'Hello, World!',
44+
},
45+
);
46+
await testLine(execa`endo show greeting`, {
47+
stdout: 'Hello, World!',
48+
});
49+
};
50+
51+
/** @type {Context} */
52+
export const context = {
53+
setup: async execa => {
54+
await execa`endo make counter.js --name counter`;
55+
await execa`endo eval E(counter).incr() counter`;
56+
await execa`endo eval E(counter).incr() counter`;
57+
await execa`endo eval E(counter).incr() counter`;
58+
await execa`endo spawn greeter`;
59+
},
60+
};
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/** @import {Context, TestRoutine} from '../types' */
2+
3+
/** @type {TestRoutine} */
4+
export const section = async (execa, testLine) => {
5+
// We make a doubler mostly the same way we made the counter...
6+
await testLine(execa`endo mkguest doubler-handle doubler-agent`, {
7+
stdout: 'Object [Alleged: EndoGuest] {}',
8+
});
9+
await testLine(
10+
execa`endo make doubler.js --name doubler --powers doubler-agent`,
11+
);
12+
13+
// This creates a doubler, but the doubler cannot respond until we resolve...
14+
await testLine(execa`endo inbox`, {
15+
stdout:
16+
/^0\. "doubler-handle" requested "a counter, suitable for doubling"/,
17+
});
18+
await testLine(execa`endo resolve 0 counter`);
19+
20+
// Now we can get a response from the doubler.
21+
await testLine(execa`endo eval E(doubler).incr() doubler`, {
22+
stdout: '8',
23+
});
24+
await testLine(execa`endo eval E(doubler).incr() doubler`, {
25+
stdout: '10',
26+
});
27+
await testLine(execa`endo eval E(doubler).incr() doubler`, {
28+
stdout: '12',
29+
});
30+
31+
// Also, in the optional second argument to request, doubler.js names...
32+
await testLine(execa`endo restart`);
33+
await testLine(execa`endo eval E(doubler).incr() doubler`, {
34+
stdout: '2',
35+
});
36+
await testLine(execa`endo eval E(doubler).incr() doubler`, {
37+
stdout: '4',
38+
});
39+
await testLine(execa`endo eval E(doubler).incr() doubler`, {
40+
stdout: '6',
41+
});
42+
};
43+
44+
/** @type {Context} */
45+
export const context = {
46+
setup: async execa => {
47+
await execa`endo mkguest doubler-handle doubler-agent`;
48+
await execa`endo make doubler.js --name doubler --powers doubler-agent`;
49+
await execa`endo inbox`;
50+
await execa`endo resolve 0 counter`;
51+
},
52+
};

packages/cli/test/demo/index.test.js

+69
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { $ } from 'execa';
33
import { makeSectionTest } from '../section.js';
44
import { withContext } from '../with-context.js';
55
import { daemonContext } from '../daemon-context.js';
6+
import * as counterExample from './counter-example.js';
7+
import * as doublerAgent from './doubler-agent.js';
8+
import * as confinedScript from './confined-script.js';
9+
import * as sendingMessages from './sending-messages.js';
10+
import * as namesInTransit from './names-in-transit.js';
11+
import * as mailboxesAreSymmetric from './mailboxes-are-symmetric.js';
612

713
test.serial(
814
'trivial',
@@ -14,3 +20,66 @@ test.serial(
1420
}),
1521
),
1622
);
23+
24+
test.serial(
25+
'counter-example',
26+
makeSectionTest(
27+
$({ cwd: 'demo' }),
28+
withContext(daemonContext)(counterExample.section),
29+
),
30+
);
31+
32+
test.serial(
33+
'doubler-agent',
34+
makeSectionTest(
35+
$({ cwd: 'demo' }),
36+
withContext(daemonContext, counterExample.context)(doublerAgent.section),
37+
),
38+
);
39+
40+
test.serial.failing(
41+
'sending-messages',
42+
makeSectionTest(
43+
$({ cwd: 'demo' }),
44+
withContext(
45+
daemonContext,
46+
counterExample.context,
47+
doublerAgent.context,
48+
)(sendingMessages.section),
49+
),
50+
);
51+
52+
test.serial.failing(
53+
'names-in-transit',
54+
makeSectionTest(
55+
$({ cwd: 'demo' }),
56+
withContext(
57+
daemonContext,
58+
counterExample.context,
59+
doublerAgent.context,
60+
sendingMessages.context,
61+
)(namesInTransit.section),
62+
),
63+
);
64+
65+
test.serial.failing(
66+
'mailboxes-are-symmetric',
67+
makeSectionTest(
68+
$({ cwd: 'demo' }),
69+
withContext(
70+
daemonContext,
71+
counterExample.context,
72+
doublerAgent.context,
73+
sendingMessages.context,
74+
namesInTransit.context,
75+
)(mailboxesAreSymmetric.section),
76+
),
77+
);
78+
79+
test.serial(
80+
'confined-script',
81+
makeSectionTest(
82+
$({ cwd: 'demo' }),
83+
withContext(daemonContext)(confinedScript.section),
84+
),
85+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @import {TestRoutine} from '../types' */
2+
3+
/** @type {TestRoutine} */
4+
export const section = async (execa, testLine) => {
5+
// Guests can also send their host messages...
6+
await testLine(
7+
execa`endo send HOST --as alice-agent ${'This is the @doubler you sent me.'}`,
8+
);
9+
await testLine(execa`endo inbox`, {
10+
stdout: /^0\. "alice" sent "This is the @doubler you sent me\."/,
11+
});
12+
await testLine(execa`endo adopt 0 doubler doubler-from-alice`);
13+
await testLine(execa`endo dismiss 0`);
14+
};
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/** @import {Context, TestRoutine} from '../types' */
2+
3+
/** @type {TestRoutine} */
4+
export const section = async (execa, testLine) => {
5+
// In this example, we send alice our "doubler" but let it appear...
6+
await testLine(
7+
execa`endo send alice ${'Please enjoy this @counter:doubler.'}`,
8+
);
9+
await testLine(execa`endo inbox --as alice-agent`, {
10+
stdout: /^1\. "HOST" sent "Please enjoy this @counter\."/,
11+
});
12+
await testLine(execa`endo adopt --as alice-agent 1 counter --name redoubler`);
13+
await testLine(execa`endo list --as alice-agent`, {
14+
stdout: 'redoubler',
15+
});
16+
await testLine(execa`endo dismiss --as alice-agent 1`);
17+
};
18+
19+
/** @type {Context} */
20+
export const context = {
21+
setup: async execa => {
22+
await execa`endo send alice ${'Please enjoy this @counter:doubler.'}`;
23+
await execa`endo inbox --as alice-agent`;
24+
await execa`endo adopt --as alice-agent 1 counter --name redoubler`;
25+
await execa`endo dismiss --as alice-agent 1`;
26+
},
27+
};
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** @import {Context, TestRoutine} from '../types' */
2+
3+
/** @type {TestRoutine} */
4+
export const section = async (execa, testLine) => {
5+
// So far, we have run guest programs like the doubler. Guests and hosts can exchange messages...
6+
await testLine(execa`endo mkguest alice alice-agent`, {
7+
stdout: 'Object [Alleged: EndoGuest] {}',
8+
});
9+
await testLine(execa`endo send alice ${'Please enjoy this @doubler.'}`);
10+
await testLine(execa`endo inbox --as alice-agent`, {
11+
stdout: /^0\. "HOST" sent "Please enjoy this @doubler\."/,
12+
});
13+
await testLine(execa`endo adopt --as alice-agent 0 doubler`);
14+
await testLine(execa`endo list --as alice-agent`, {
15+
stdout: 'doubler',
16+
});
17+
await testLine(execa`endo dismiss --as alice-agent 0`);
18+
};
19+
20+
/** @type {Context} */
21+
export const context = {
22+
setup: async execa => {
23+
await execa`endo mkguest alice alice-agent`;
24+
await execa`endo send alice ${'Please enjoy this @doubler.'}`;
25+
await execa`endo adopt alice-agent 0 doubler`;
26+
await execa`endo dismiss --as alice-agent 0`;
27+
},
28+
};

0 commit comments

Comments
 (0)