-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cli): Add demo section tests, excluding familiar-chat
- Loading branch information
Showing
7 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @import {TestRoutine} from '../types */ | ||
|
||
/** @type {TestRoutine} */ | ||
export const section = async (execa, testLine) => { | ||
// If a runlet returns a promise for some value, it will print that value before exiting gracefully. | ||
await testLine(execa`endo run runlet.js a b c`, { | ||
stdout: "Hello, World! [ 'a', 'b', 'c' ]\n42", | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** @import {Context, TestRoutine} from '../types' */ | ||
|
||
/** @type {TestRoutine} */ | ||
export const section = async (execa, testLine) => { | ||
// We can create an instance of the counter and give it a name. | ||
await testLine(execa`endo make counter.js --name counter`, { | ||
stdout: 'Object [Alleged: Counter] {}', | ||
}); | ||
|
||
// Then, we can send messages to the counter and see their responses... | ||
await testLine(execa`endo eval E(counter).incr() counter`, { | ||
stdout: '1', | ||
}); | ||
await testLine(execa`endo eval E(counter).incr() counter`, { | ||
stdout: '2', | ||
}); | ||
await testLine(execa`endo eval E(counter).incr() counter`, { | ||
stdout: '3', | ||
}); | ||
|
||
// Aside: in all the above cases, we use counter both as the property name... | ||
await testLine(execa`endo eval E(c).incr() c:counter`, { | ||
stdout: '4', | ||
}); | ||
|
||
// Endo preserves the commands that led to the creation of the counter value... | ||
await testLine(execa`endo restart`); | ||
await testLine(execa`endo eval E(counter).incr() counter`, { | ||
stdout: '1', | ||
}); | ||
await testLine(execa`endo eval E(counter).incr() counter`, { | ||
stdout: '2', | ||
}); | ||
await testLine(execa`endo eval E(counter).incr() counter`, { | ||
stdout: '3', | ||
}); | ||
|
||
// Aside, since Eventual Send, the machinery under the E operator... | ||
await testLine(execa`endo spawn greeter`); | ||
await testLine( | ||
execa`endo eval --worker greeter '${'Hello, World!'}' --name greeting`, | ||
{ | ||
stdout: 'Hello, World!', | ||
}, | ||
); | ||
await testLine(execa`endo show greeting`, { | ||
stdout: 'Hello, World!', | ||
}); | ||
}; | ||
|
||
/** @type {Context} */ | ||
export const context = { | ||
setup: async execa => { | ||
await execa`endo make counter.js --name counter`; | ||
await execa`endo eval E(counter).incr() counter`; | ||
await execa`endo eval E(counter).incr() counter`; | ||
await execa`endo eval E(counter).incr() counter`; | ||
await execa`endo spawn greeter`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** @import {Context, TestRoutine} from '../types' */ | ||
|
||
/** @type {TestRoutine} */ | ||
export const section = async (execa, testLine) => { | ||
// We make a doubler mostly the same way we made the counter... | ||
await testLine(execa`endo mkguest doubler-handle doubler-agent`, { | ||
stdout: 'Object [Alleged: EndoGuest] {}', | ||
}); | ||
await testLine( | ||
execa`endo make doubler.js --name doubler --powers doubler-agent`, | ||
); | ||
|
||
// This creates a doubler, but the doubler cannot respond until we resolve... | ||
await testLine(execa`endo inbox`, { | ||
stdout: | ||
/^0\. "doubler-handle" requested "a counter, suitable for doubling"/, | ||
}); | ||
await testLine(execa`endo resolve 0 counter`); | ||
|
||
// Now we can get a response from the doubler. | ||
await testLine(execa`endo eval E(doubler).incr() doubler`, { | ||
stdout: '8', | ||
}); | ||
await testLine(execa`endo eval E(doubler).incr() doubler`, { | ||
stdout: '10', | ||
}); | ||
await testLine(execa`endo eval E(doubler).incr() doubler`, { | ||
stdout: '12', | ||
}); | ||
|
||
// Also, in the optional second argument to request, doubler.js names... | ||
await testLine(execa`endo restart`); | ||
await testLine(execa`endo eval E(doubler).incr() doubler`, { | ||
stdout: '2', | ||
}); | ||
await testLine(execa`endo eval E(doubler).incr() doubler`, { | ||
stdout: '4', | ||
}); | ||
await testLine(execa`endo eval E(doubler).incr() doubler`, { | ||
stdout: '6', | ||
}); | ||
}; | ||
|
||
/** @type {Context} */ | ||
export const context = { | ||
setup: async execa => { | ||
await execa`endo mkguest doubler-handle doubler-agent`; | ||
await execa`endo make doubler.js --name doubler --powers doubler-agent`; | ||
await execa`endo inbox`; | ||
await execa`endo resolve 0 counter`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @import {TestRoutine} from '../types' */ | ||
|
||
/** @type {TestRoutine} */ | ||
export const section = async (execa, testLine) => { | ||
// Guests can also send their host messages... | ||
await testLine( | ||
execa`endo send HOST --as alice-agent ${'This is the @doubler you sent me.'}`, | ||
); | ||
await testLine(execa`endo inbox`, { | ||
stdout: /^0\. "alice" sent "This is the @doubler you sent me\."/, | ||
}); | ||
await testLine(execa`endo adopt 0 doubler doubler-from-alice`); | ||
await testLine(execa`endo dismiss 0`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** @import {Context, TestRoutine} from '../types' */ | ||
|
||
/** @type {TestRoutine} */ | ||
export const section = async (execa, testLine) => { | ||
// In this example, we send alice our "doubler" but let it appear... | ||
await testLine( | ||
execa`endo send alice ${'Please enjoy this @counter:doubler.'}`, | ||
); | ||
await testLine(execa`endo inbox --as alice-agent`, { | ||
stdout: /^1\. "HOST" sent "Please enjoy this @counter\."/, | ||
}); | ||
await testLine(execa`endo adopt --as alice-agent 1 counter --name redoubler`); | ||
await testLine(execa`endo list --as alice-agent`, { | ||
stdout: 'redoubler', | ||
}); | ||
await testLine(execa`endo dismiss --as alice-agent 1`); | ||
}; | ||
|
||
/** @type {Context} */ | ||
export const context = { | ||
setup: async execa => { | ||
await execa`endo send alice ${'Please enjoy this @counter:doubler.'}`; | ||
await execa`endo inbox --as alice-agent`; | ||
await execa`endo adopt --as alice-agent 1 counter --name redoubler`; | ||
await execa`endo dismiss --as alice-agent 1`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** @import {Context, TestRoutine} from '../types' */ | ||
|
||
/** @type {TestRoutine} */ | ||
export const section = async (execa, testLine) => { | ||
// So far, we have run guest programs like the doubler. Guests and hosts can exchange messages... | ||
await testLine(execa`endo mkguest alice alice-agent`, { | ||
stdout: 'Object [Alleged: EndoGuest] {}', | ||
}); | ||
await testLine(execa`endo send alice ${'Please enjoy this @doubler.'}`); | ||
await testLine(execa`endo inbox --as alice-agent`, { | ||
stdout: /^0\. "HOST" sent "Please enjoy this @doubler\."/, | ||
}); | ||
await testLine(execa`endo adopt --as alice-agent 0 doubler`); | ||
await testLine(execa`endo list --as alice-agent`, { | ||
stdout: 'doubler', | ||
}); | ||
await testLine(execa`endo dismiss --as alice-agent 0`); | ||
}; | ||
|
||
/** @type {Context} */ | ||
export const context = { | ||
setup: async execa => { | ||
await execa`endo mkguest alice alice-agent`; | ||
await execa`endo send alice ${'Please enjoy this @doubler.'}`; | ||
await execa`endo adopt alice-agent 0 doubler`; | ||
await execa`endo dismiss --as alice-agent 0`; | ||
}, | ||
}; |