Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions etc/blocks/nonpure-output/.structure
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1}
1 change: 1 addition & 0 deletions etc/blocks/nonpure-output/block/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
6 changes: 6 additions & 0 deletions etc/blocks/nonpure-output/block/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare const blockSpec: {
type: "dev-v2";
folder: string;
};

export { blockSpec };
8 changes: 8 additions & 0 deletions etc/blocks/nonpure-output/block/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const blockSpec = {
type: "dev-v2",
folder: __dirname,
};

module.exports = {
blockSpec,
};
40 changes: 40 additions & 0 deletions etc/blocks/nonpure-output/block/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@milaboratories/milaboratories.test-nonpure-output",
"version": "1.0.127",
"private": true,
"files": [
"index.d.ts",
"index.js"
],
"scripts": {
"build": "shx rm -rf ./block-pack && block-tools pack",
"mark-stable": "block-tools mark-stable -r 's3://milab-euce1-prod-pkgs-s3-block-registry/pub/releases/?region=eu-central-1'",
"prepublishOnly": "block-tools pack && block-tools publish -r 's3://milab-euce1-prod-pkgs-s3-block-registry/pub/releases/?region=eu-central-1'",
"do-pack": "shx rm -f *.tgz && block-tools pack && pnpm pack && shx mv *.tgz package.tgz"
},
"dependencies": {
"@milaboratories/milaboratories.test-nonpure-output.model": "workspace:*",
"@milaboratories/milaboratories.test-nonpure-output.ui": "workspace:*",
"@milaboratories/milaboratories.test-nonpure-output.workflow": "workspace:*",
"@platforma-sdk/model": "workspace:*"
},
"devDependencies": {
"@platforma-sdk/block-tools": "workspace:*",
"shx": "catalog:"
},
"block": {
"components": {
"workflow": "@milaboratories/milaboratories.test-nonpure-output.workflow/dist/tengo/tpl/main.plj.gz",
"model": "@milaboratories/milaboratories.test-nonpure-output.model/dist/model.json",
"ui": "@milaboratories/milaboratories.test-nonpure-output.ui/dist"
},
"meta": {
"title": "Non-pure Output (CID conflict repro)",
"description": "Test block whose command emits a different value every run, reproducing the recover-mode CID conflict",
"organization": {
"name": "MiLaboratories Inc",
"url": "https://milaboratories.com/"
}
}
}
}
4 changes: 4 additions & 0 deletions etc/blocks/nonpure-output/model/.oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["node_modules/@milaboratories/ts-builder/configs/oxfmt.json"],
"ignorePatterns": ["dist", "coverage", "CHANGELOG.md"]
}
3 changes: 3 additions & 0 deletions etc/blocks/nonpure-output/model/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["node_modules/@milaboratories/ts-builder/dist/configs/oxlint-block-model.json"]
}
1 change: 1 addition & 0 deletions etc/blocks/nonpure-output/model/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
42 changes: 42 additions & 0 deletions etc/blocks/nonpure-output/model/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@milaboratories/milaboratories.test-nonpure-output.model",
"version": "1.0.34",
"private": true,
"description": "Block model",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"sources": "./src/index.ts",
"import": "./dist/index.js"
},
"./dist/*": "./dist/*"
},
"scripts": {
"build": "ts-builder build --target block-model && block-tools build-model",
"check": "ts-builder check --target block-model",
"formatter:check": "ts-builder formatter --check",
"linter:check": "ts-builder linter --check",
"types:check": "ts-builder type-check --target block-model",
"fmt": "ts-builder format",
"watch": "ts-builder build --target block-model --watch"
},
"dependencies": {
"@platforma-sdk/model": "workspace:*",
"zod": "catalog:"
},
"devDependencies": {
"@milaboratories/build-configs": "workspace:*",
"@milaboratories/ts-builder": "workspace:*",
"@milaboratories/ts-configs": "workspace:*",
"@platforma-sdk/block-tools": "workspace:*",
"vitest": "catalog:"
},
"peerDependencies": {
"@types/node": "*",
"typescript": "*"
}
}
27 changes: 27 additions & 0 deletions etc/blocks/nonpure-output/model/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { InferHrefType, InferOutputsType } from "@platforma-sdk/model";
import { BlockModel } from "@platforma-sdk/model";
import { z } from "zod";

// The block takes no inputs: it just runs an impure command. argsValid is always
// true, so the workflow runs as soon as the block is created.
export const BlockArgs = z.object({});

export type BlockArgs = z.infer<typeof BlockArgs>;

export const platforma = BlockModel.create("Heavy")

.withArgs<BlockArgs>({})

// The non-deterministic value produced by the workflow command (changes every run).
.output("nonpureValue", (ctx) => ctx.outputs?.resolve("nonpureValue")?.getDataAsString())

.argsValid(() => true)

.sections((_ctx) => {
return [{ type: "link", href: "/", label: "Main" }];
})

.done(2); // ui api version 2

export type BlockOutputs = InferOutputsType<typeof platforma>;
export type Href = InferHrefType<typeof platforma>;
4 changes: 4 additions & 0 deletions etc/blocks/nonpure-output/model/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@milaboratories/ts-configs/block/model",
"include": ["src/**/*"]
}
42 changes: 42 additions & 0 deletions etc/blocks/nonpure-output/software/random-gen/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@platforma-open/milaboratories.test-nonpure-output.random-gen",
"version": "1.0.0",
"private": true,
"description": "Impure command: prints a fresh random value on every run",
"scripts": {
"build": "shx rm -rf ./dist && pl-pkg build",
"prepublishOnly": "pl-pkg prepublish",
"do-pack": "shx rm -f *.tgz && pl-pkg build && pnpm pack && shx mv platforma-open-*.tgz package.tgz"
},
"files": [
"./dist/**/*"
],
"dependencies": {},
"devDependencies": {
"@platforma-sdk/package-builder": "workspace:*",
"@platforma-open/milaboratories.runenv-python-3": "catalog:",
"shx": "catalog:"
},
"block-software": {
"entrypoints": {
"main": {
"binary": {
"artifact": {
"type": "python",
"registry": "platforma-open",
"environment": "@platforma-open/milaboratories.runenv-python-3:3.12.10",
"dependencies": {
"toolset": "pip",
"requirements": "requirements.txt"
},
"root": "./src"
},
"cmd": [
"python",
"{pkg}/main.py"
]
}
}
}
}
}
20 changes: 20 additions & 0 deletions etc/blocks/nonpure-output/software/random-gen/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
"""Impure helper for the non-pure-output test block.

Prints a fresh random token on every run, so the same (empty) inputs produce a
different output each time. That is exactly what makes a block built on it
non-pure, and what triggers the recover-mode CID conflict in the backend: the
recovered (predicted) output CID diverges from the recomputed one.

Stdlib only - cross-platform, no third-party dependencies.
"""

import secrets


def main() -> None:
print(secrets.token_hex(16))
Comment thread
xnacly marked this conversation as resolved.
Outdated


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# No third-party dependencies - main.py uses the Python standard library only.
3 changes: 3 additions & 0 deletions etc/blocks/nonpure-output/ui/.oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignorePatterns": ["dist", "CHANGELOG.md"]
}
3 changes: 3 additions & 0 deletions etc/blocks/nonpure-output/ui/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["node_modules/@milaboratories/ts-builder/dist/configs/oxlint-block-ui.json"]
}
1 change: 1 addition & 0 deletions etc/blocks/nonpure-output/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
12 changes: 12 additions & 0 deletions etc/blocks/nonpure-output/ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' blob:" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions etc/blocks/nonpure-output/ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@milaboratories/milaboratories.test-nonpure-output.ui",
"version": "1.0.117",
"private": true,
"type": "module",
"scripts": {
"dev": "ts-builder serve --target block-ui",
"watch": "ts-builder build --target block-ui --watch",
"check": "ts-builder check --target block-ui",
"formatter:check": "ts-builder formatter --check",
"linter:check": "ts-builder linter --check",
"types:check": "ts-builder type-check --target block-ui",
"build": "ts-builder build --target block-ui",
"fmt": "ts-builder format"
},
"dependencies": {
"@milaboratories/milaboratories.test-nonpure-output.model": "workspace:*",
"@platforma-sdk/ui-vue": "workspace:*",
"vue": "catalog:"
},
"devDependencies": {
"@faker-js/faker": "catalog:",
"@milaboratories/build-configs": "workspace:*",
"@milaboratories/helpers": "workspace:*",
"@milaboratories/ts-builder": "workspace:*",
"@milaboratories/ts-configs": "workspace:*",
"vitest": "catalog:",
"zod": "catalog:"
},
"peerDependencies": {
"@types/node": "*",
"typescript": "*"
}
}
19 changes: 19 additions & 0 deletions etc/blocks/nonpure-output/ui/src/MainPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup lang="ts">
import { PlAlert, PlBlockPage } from "@platforma-sdk/ui-vue";
import { useApp } from "./app";

const app = useApp();
</script>

<template>
<PlBlockPage style="max-width: 100%">
<PlAlert type="info" monospace>
Non-pure output (changes on every run):
{{ app.model.outputs.nonpureValue }}
</PlAlert>

<PlAlert v-if="app.error" type="error">
{{ app.error }}
</PlAlert>
Comment thread
xnacly marked this conversation as resolved.
Outdated
</PlBlockPage>
</template>
39 changes: 39 additions & 0 deletions etc/blocks/nonpure-output/ui/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { platforma } from "@milaboratories/milaboratories.test-nonpure-output.model";
import MainPage from "./MainPage.vue";
import { defineApp } from "@platforma-sdk/ui-vue";
import type { Component } from "vue";
import { computed, reactive } from "vue";
import type { Equal, Expect } from "@milaboratories/helpers";

export const sdkPlugin = defineApp(platforma, (base) => {
// Additional data
const data = reactive({
counter: 0,
});

function incrementCounter() {
data.counter++;
}

const argsAsJson = computed(() => JSON.stringify(base.snapshot.args));

return {
data,
incrementCounter,
argsAsJson,
routes: {
"/": () => MainPage,
},
};
});
Comment thread
xnacly marked this conversation as resolved.
Outdated

type App = ReturnType<typeof sdkPlugin.useApp>;

type __cases = [
Expect<Equal<App["incrementCounter"], () => void>>,
Expect<Equal<App["data"], { counter: number }>>,
Expect<Equal<App["argsAsJson"], string>>,
Expect<Equal<App["getRoute"], (href: "/") => Component | undefined>>,
];
Comment thread
xnacly marked this conversation as resolved.
Outdated

export const useApp = sdkPlugin.useApp;
Comment thread
xnacly marked this conversation as resolved.
5 changes: 5 additions & 0 deletions etc/blocks/nonpure-output/ui/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createApp } from "vue";
import { sdkPlugin } from "./app";
import { BlockLayout } from "@platforma-sdk/ui-vue";

createApp(BlockLayout).use(sdkPlugin).mount("#app");
4 changes: 4 additions & 0 deletions etc/blocks/nonpure-output/ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@milaboratories/ts-configs/block/ui",
"include": ["src/**/*"]
}
1 change: 1 addition & 0 deletions etc/blocks/nonpure-output/workflow/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
42 changes: 42 additions & 0 deletions etc/blocks/nonpure-output/workflow/format.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; This program formats all files inside src directory. Usage: emacs --script ./format.el

(defun install-go-mode ()
"Installs go-mode"
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))

(package-install 'go-mode t)
(require 'go-mode))

;; spaces -> tabs only at the beginning of lines
(setq tabify-regexp "^\t* [ \t]+")

(defun format-file (file)
"Formats a file according to slightly changed Go rules"
(message "Format %s" file)
(save-excursion
(find-file file)
(delete-trailing-whitespace) ;; deletes whitespaces
(go-mode) ;; sets golang rules for indentation
(tabify (point-min) (point-max)) ;; spaces -> tabs in the whole file
(indent-region (point-min) (point-max)) ;; indentation in the whole file
(save-buffer))) ;; save file

(install-go-mode)

;; change syntax of a standard go-mode a bit
(advice-add
'go--in-composite-literal-p
:filter-return
(lambda (&rest r) t))

;; find all files in src
(setq files (directory-files-recursively "src" "\\.tengo\\'"))

;; call format on every file.
(dolist (file files)
(format-file file))
Loading
Loading