-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5fd6ca
commit 12279c4
Showing
26 changed files
with
2,529 additions
and
886 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,111 @@ | ||
import { toPromise } from '@holochain-open-dev/signals'; | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { cleanNodeDecoding } from '@holochain-open-dev/utils/dist/clean-node-decoding.js'; | ||
import { | ||
ActionHash, | ||
Delete, | ||
Record, | ||
SignedActionHashed, | ||
encodeHashToBase64, | ||
} from '@holochain/client'; | ||
import { dhtSync, pause, runScenario } from '@holochain/tryorama'; | ||
import { decode } from '@msgpack/msgpack'; | ||
import { assert, expect, test } from 'vitest'; | ||
|
||
import { sampleTask } from '../../ui/src/mocks.js'; | ||
import { Task } from '../../ui/src/types.js'; | ||
import { waitUntil } from '../../ui/src/utils.js'; | ||
import { setup } from './setup.js'; | ||
|
||
test('create and update Task', async () => { | ||
await runScenario(async scenario => { | ||
const { alice, bob } = await setup(scenario); | ||
|
||
// Alice creates a Task | ||
const dependency: EntryRecord<Task> = await alice.store.client.createTask( | ||
await sampleTask(alice.store.client), | ||
); | ||
assert.ok(dependency); | ||
const originalDependencyActionHash = dependency.actionHash; | ||
|
||
// Bob creates a dependent Task | ||
const dependent: EntryRecord<Task> = await alice.store.client.createTask( | ||
await sampleTask(alice.store.client, { | ||
status: 'Blocked', | ||
dependencies: [ | ||
{ | ||
original_revision_hash: dependency.actionHash, | ||
last_revision_hash: dependency.actionHash, | ||
optional: false, | ||
status: 'Ready', | ||
}, | ||
], | ||
}), | ||
); | ||
const originalDependentActionHash = dependent.actionHash; | ||
assert.ok(dependency); | ||
|
||
const dependentTasks = await toPromise( | ||
alice.store.tasks.get(dependency.actionHash).dependentTasks.live, | ||
); | ||
assert.equal(dependentTasks.length, 1); | ||
assert.equal( | ||
encodeHashToBase64(dependentTasks[0]), | ||
encodeHashToBase64(dependent.actionHash), | ||
); | ||
|
||
// Task is not ready: it's blocked by its dependency | ||
await expect(() => | ||
bob.store.client.updateTask( | ||
originalDependentActionHash, | ||
dependent.actionHash, | ||
{ | ||
...dependent.entry, | ||
original_create_hash: originalDependentActionHash, | ||
status: 'Ready', | ||
}, | ||
), | ||
).rejects.toThrowError(); | ||
|
||
await alice.store.client.updateTask( | ||
originalDependencyActionHash, | ||
dependency.actionHash, | ||
{ | ||
...dependency.entry, | ||
original_create_hash: originalDependencyActionHash, | ||
status: 'Done', | ||
}, | ||
); | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync([alice.player, bob.player], alice.player.cells[0].cell_id[0]); | ||
|
||
// await bob.store.client.updateTask( | ||
// originalDependentActionHash, | ||
// dependent.actionHash, | ||
// { | ||
// ...dependent.entry, | ||
// dependencies: [ | ||
// { | ||
// original_revision_hash: dependency.actionHash, | ||
// last_revision_hash: updatedDependency.actionHash, | ||
// optional: false, | ||
// status: 'Done', | ||
// }, | ||
// ], | ||
// status: 'Ready', | ||
// }, | ||
// ); | ||
|
||
// Task status should be automatically updated by the store | ||
await waitUntil( | ||
async () => | ||
( | ||
await toPromise( | ||
bob.store.tasks.get(dependent.actionHash).latestVersion, | ||
) | ||
).entry.status === 'Ready', | ||
30_000, | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,62 +1,70 @@ | ||
import { | ||
AgentPubKey, | ||
EntryHash, | ||
NewEntryAction, | ||
ActionHash, | ||
Record, | ||
AppBundleSource, | ||
fakeActionHash, | ||
fakeAgentPubKey, | ||
fakeEntryHash, | ||
fakeDnaHash, | ||
AppCallZomeRequest, | ||
AppWebsocket, | ||
encodeHashToBase64 | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { | ||
ActionHash, | ||
AgentPubKey, | ||
AppBundleSource, | ||
AppCallZomeRequest, | ||
AppWebsocket, | ||
EntryHash, | ||
NewEntryAction, | ||
Record, | ||
encodeHashToBase64, | ||
fakeActionHash, | ||
fakeAgentPubKey, | ||
fakeDnaHash, | ||
fakeEntryHash, | ||
} from '@holochain/client'; | ||
import { encode } from '@msgpack/msgpack'; | ||
import { Scenario } from '@holochain/tryorama'; | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { encode } from '@msgpack/msgpack'; | ||
import { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
import { TasksClient } from '../../ui/src/tasks-client.js'; | ||
import { TasksStore } from '../../ui/src/tasks-store.js'; | ||
|
||
export async function setup(scenario: Scenario) { | ||
const testHappUrl = | ||
dirname(fileURLToPath(import.meta.url)) + '/../../workdir/tasks_test.happ'; | ||
|
||
// Add 2 players with the test hApp to the Scenario. The returned players | ||
// can be destructured. | ||
const [alice, bob] = await scenario.addPlayersWithApps([ | ||
{ appBundleSource: { path: testHappUrl } }, | ||
{ appBundleSource: { path: testHappUrl } }, | ||
]); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
const aliceStore = new TasksStore( | ||
new TasksClient(alice.appWs as any, 'tasks_test', 'tasks') | ||
); | ||
|
||
const bobStore = new TasksStore( | ||
new TasksClient(bob.appWs as any, 'tasks_test', 'tasks') | ||
); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
return { | ||
alice: { | ||
player: alice, | ||
store: aliceStore, | ||
}, | ||
bob: { | ||
player: bob, | ||
store: bobStore, | ||
}, | ||
}; | ||
} | ||
const testHappUrl = | ||
dirname(fileURLToPath(import.meta.url)) + '/../../workdir/tasks_test.happ'; | ||
|
||
// Add 2 players with the test hApp to the Scenario. The returned players | ||
// can be destructured. | ||
const [alice, bob] = await scenario.addPlayersWithApps([ | ||
{ appBundleSource: { path: testHappUrl } }, | ||
{ appBundleSource: { path: testHappUrl } }, | ||
]); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
await alice.conductor | ||
.adminWs() | ||
.authorizeSigningCredentials(alice.cells[0].cell_id); | ||
|
||
await bob.conductor | ||
.adminWs() | ||
.authorizeSigningCredentials(bob.cells[0].cell_id); | ||
|
||
const aliceStore = new TasksStore( | ||
new TasksClient(alice.appWs as any, 'tasks_test', 'tasks'), | ||
); | ||
|
||
const bobStore = new TasksStore( | ||
new TasksClient(bob.appWs as any, 'tasks_test', 'tasks'), | ||
); | ||
|
||
// Shortcut peer discovery through gossip and register all agents in every | ||
// conductor of the scenario. | ||
await scenario.shareAllAgents(); | ||
|
||
return { | ||
alice: { | ||
player: alice, | ||
store: aliceStore, | ||
}, | ||
bob: { | ||
player: bob, | ||
store: bobStore, | ||
}, | ||
}; | ||
} |
Oops, something went wrong.