Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.2

- Reject an updated binding that omits a required precondition, preserving the previous working binding.

## 1.0.1

- Keep project-file reads tied to the checked descriptor and reject a swapped path before generating or applying an integration.
Expand Down
2 changes: 1 addition & 1 deletion examples/catalog/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "latch-example-catalog",
"private": true,
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"scripts": {
"dev": "vite --host 127.0.0.1 --port 5173 --strictPort",
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "latch-example-docs",
"private": true,
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"scripts": {
"dev": "vite --host 127.0.0.1 --port 5174 --strictPort",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "latch-release-workspace",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"type": "module",
"packageManager": "pnpm@10.17.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @latch-local/browser 1.0.1
# @latch-local/browser 1.0.2

Part of Latch: Connect your site. Verify every action.

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@latch-local/browser",
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"description": "Latch browser: Connect your site. Verify every action.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @latch-local/cli 1.0.1
# @latch-local/cli 1.0.2

Part of Latch: Connect your site. Verify every action.

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@latch-local/cli",
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"description": "Latch cli: Connect your site. Verify every action.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '1.0.1';
export const VERSION = '1.0.2';
2 changes: 1 addition & 1 deletion packages/console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@latch-local/console-source",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"type": "module",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @latch-local/contracts 1.0.1
# @latch-local/contracts 1.0.2

Part of Latch: Connect your site. Verify every action.

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@latch-local/contracts",
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"description": "Latch contracts: Connect your site. Verify every action.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @latch-local/react 1.0.1
# @latch-local/react 1.0.2

Part of Latch: Connect your site. Verify every action.

Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@latch-local/react",
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"description": "Latch react: Connect your site. Verify every action.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @latch-local/runtime 1.0.1
# @latch-local/runtime 1.0.2

Part of Latch: Connect your site. Verify every action.

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@latch-local/runtime",
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"description": "Latch runtime: Connect your site. Verify every action.",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export function createScope(bindings: Binding[], options: ScopeOptions = {}) {
)
)
throw new LatchError('BINDING', 'Contracts changed: remount the scope');
for (const b of next)
for (const p of b.contract.preconditions)
if (typeof b.preconditions?.[p] !== 'function')
throw new LatchError('PRECONDITION', `${b.contract.name}: missing precondition ${p}`);
current = next;
},
dispose() {
Expand Down
2 changes: 1 addition & 1 deletion packages/test/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @latch-local/test 1.0.1
# @latch-local/test 1.0.2

Part of Latch: Connect your site. Verify every action.

Expand Down
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@latch-local/test",
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"description": "Latch test: Connect your site. Verify every action.",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions tests/generator.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ test('a valid 0.1.0 ownership manifest upgrades and keeps rollback protection',
generate(r);
apply(r);
const output = path.join(r, 'src/latch.generated/integration.ts');
fs.writeFileSync(output, fs.readFileSync(output, 'utf8').replace('Latch 1.0.1.', 'Latch 0.1.0.'));
fs.writeFileSync(output, fs.readFileSync(output, 'utf8').replace('Latch 1.0.2.', 'Latch 0.1.0.'));
const manifestPath = path.join(r, '.latch/manifest.json');
const old = JSON.parse(fs.readFileSync(manifestPath));
old.generatorVersion = '0.1.0';
old.files['src/latch.generated/integration.ts'].after = createHash('sha256').update(fs.readFileSync(output)).digest('hex');
fs.writeFileSync(manifestPath, JSON.stringify(old));
generate(r);
assert.equal(JSON.parse(fs.readFileSync(manifestPath)).generatorVersion, '1.0.1');
assert.equal(JSON.parse(fs.readFileSync(manifestPath)).generatorVersion, '1.0.2');
assert.equal(check(r).installation, 'applied');
rollback(r);
assert.equal(fs.readFileSync(path.join(r, 'src/main.tsx'), 'utf8'), before);
Expand Down
35 changes: 35 additions & 0 deletions tests/runtime.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,41 @@ test('preconditions are evaluated at execution time', async () => {
assert.deepEqual(await s.invoke('search', { q: 'x' }), { q: 'x' });
s.dispose();
});
test('update rejects a missing required precondition and keeps the prior binding', async () => {
const guarded = { ...contract, preconditions: ['allowed'] };
let originalCalls = 0;
let replacementCalls = 0;
const s = createScope(
[
{
contract: guarded,
handler: (x) => {
originalCalls++;
return x;
},
preconditions: { allowed: () => true },
},
],
{ adapter: unsupported },
);
assert.throws(
() =>
s.update([
{
contract: guarded,
handler: (x) => {
replacementCalls++;
return x;
},
},
]),
{ code: 'PRECONDITION' },
);
assert.deepEqual(await s.invoke('search', { q: 'still authorized' }), { q: 'still authorized' });
assert.equal(originalCalls, 1);
assert.equal(replacementCalls, 0);
s.dispose();
});
test('unsupported browser is a status, not a fake native API', async () => {
const s = createScope([binding((x) => x)], { adapter: unsupported });
assert.equal((await s.ready).registration, 'unsupported');
Expand Down
Loading