Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
Rick Carlino | be38ad830a | |
Rick Carlino | 4f03626d5f | |
Rick Carlino | bc68f3e79f | |
Rick Carlino | bce0700cd9 | |
Rick Carlino | 9f1cf4eedd | |
Rick Carlino | afceaf25e0 | |
Rick Carlino | e5389b747e | |
Rick Carlino | a5b1d5631e |
|
@ -16,9 +16,9 @@ module CeleryScriptSettingsBag
|
||||||
end
|
end
|
||||||
|
|
||||||
PIN_TYPE_MAP = { "Peripheral" => Peripheral,
|
PIN_TYPE_MAP = { "Peripheral" => Peripheral,
|
||||||
"Sensor" => Sensor,
|
"Sensor" => Sensor,
|
||||||
"BoxLed3" => BoxLed,
|
"BoxLed3" => BoxLed,
|
||||||
"BoxLed4" => BoxLed }
|
"BoxLed4" => BoxLed }
|
||||||
ALLOWED_AXIS = %w(x y z all)
|
ALLOWED_AXIS = %w(x y z all)
|
||||||
ALLOWED_ASSERTION_TYPES = %w(abort recover abort_recover continue)
|
ALLOWED_ASSERTION_TYPES = %w(abort recover abort_recover continue)
|
||||||
ALLOWED_CHANGES = %w(add remove update)
|
ALLOWED_CHANGES = %w(add remove update)
|
||||||
|
@ -251,7 +251,9 @@ module CeleryScriptSettingsBag
|
||||||
# outside of the API. If `package` _was_ declared as a native enum (rather
|
# outside of the API. If `package` _was_ declared as a native enum (rather
|
||||||
# than a string), it would cause false type errors in FE/FBJS.
|
# than a string), it would cause false type errors in FE/FBJS.
|
||||||
blk: ->(node) do
|
blk: ->(node) do
|
||||||
manual_enum(ALLOWED_PACKAGES, node, BAD_PACKAGE)
|
unless node.parent.kind.to_s == "flash_firmware"
|
||||||
|
manual_enum(ALLOWED_PACKAGES, node, BAD_PACKAGE)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
axis: {
|
axis: {
|
||||||
|
@ -529,7 +531,7 @@ module CeleryScriptSettingsBag
|
||||||
resource_id = n.args.fetch(:point_group_id).value
|
resource_id = n.args.fetch(:point_group_id).value
|
||||||
check_resource_type(n, "PointGroup", resource_id, Device.current)
|
check_resource_type(n, "PointGroup", resource_id, Device.current)
|
||||||
end,
|
end,
|
||||||
}
|
},
|
||||||
}.map { |(name, list)| Corpus.node(name, **list) }
|
}.map { |(name, list)| Corpus.node(name, **list) }
|
||||||
|
|
||||||
HASH = Corpus.as_json
|
HASH = Corpus.as_json
|
||||||
|
|
|
@ -95,6 +95,11 @@ export function StepButtonCluster(props: StepButtonProps) {
|
||||||
color="brown">
|
color="brown">
|
||||||
{t("REBOOT")}
|
{t("REBOOT")}
|
||||||
</StepButton>,
|
</StepButton>,
|
||||||
|
<StepButton {...commonStepProps}
|
||||||
|
step={{ kind: "flash_firmware", args: { package: "arduino_firmware" } }}
|
||||||
|
color="brown">
|
||||||
|
{t("REFLASH FIRMWARE")}
|
||||||
|
</StepButton>,
|
||||||
<StepButton {...commonStepProps}
|
<StepButton {...commonStepProps}
|
||||||
step={{ kind: "emergency_lock", args: {} }}
|
step={{ kind: "emergency_lock", args: {} }}
|
||||||
color="red">
|
color="red">
|
||||||
|
|
|
@ -5,11 +5,6 @@ import { StepWrapper, StepHeader, StepContent } from "../step_ui/index";
|
||||||
import { t } from "../../i18next_wrapper";
|
import { t } from "../../i18next_wrapper";
|
||||||
import { ALLOWED_PACKAGES, SequenceBodyItem, Reboot } from "farmbot";
|
import { ALLOWED_PACKAGES, SequenceBodyItem, Reboot } from "farmbot";
|
||||||
import { editStep } from "../../api/crud";
|
import { editStep } from "../../api/crud";
|
||||||
// import { StepRadio } from "../step_ui/step_radio";
|
|
||||||
// const PACKAGE_CHOICES = (): Record<ALLOWED_PACKAGES, string> => ({
|
|
||||||
// "arduino_firmware": t("Just the Arduino"),
|
|
||||||
// "farmbot_os": t("Entire system")
|
|
||||||
// });
|
|
||||||
|
|
||||||
function assertReboot(x: SequenceBodyItem): asserts x is Reboot {
|
function assertReboot(x: SequenceBodyItem): asserts x is Reboot {
|
||||||
if (x.kind !== "reboot") {
|
if (x.kind !== "reboot") {
|
||||||
|
|
|
@ -6,68 +6,68 @@ describe CeleryScript::Corpus do
|
||||||
|
|
||||||
it "handles valid move_absolute blocks" do
|
it "handles valid move_absolute blocks" do
|
||||||
ok1 = CeleryScript::AstNode.new(**{
|
ok1 = CeleryScript::AstNode.new(**{
|
||||||
kind: "move_absolute",
|
kind: "move_absolute",
|
||||||
args: {
|
args: {
|
||||||
location: {
|
location: {
|
||||||
kind: "coordinate",
|
kind: "coordinate",
|
||||||
args: {
|
args: {
|
||||||
x: 1,
|
x: 1,
|
||||||
y: 2,
|
y: 2,
|
||||||
z: 3,
|
z: 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
offset: {
|
offset: {
|
||||||
kind: "coordinate",
|
kind: "coordinate",
|
||||||
args: {
|
args: {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
"z": 0,
|
"z": 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
speed: 100,
|
speed: 100,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
check1 = CeleryScript::Checker.new(ok1, corpus, device)
|
check1 = CeleryScript::Checker.new(ok1, corpus, device)
|
||||||
expect(check1.valid?).to be_truthy
|
expect(check1.valid?).to be_truthy
|
||||||
|
|
||||||
ok2 = CeleryScript::AstNode.new(**{
|
ok2 = CeleryScript::AstNode.new(**{
|
||||||
kind: "move_absolute",
|
kind: "move_absolute",
|
||||||
args: {
|
args: {
|
||||||
location: {
|
location: {
|
||||||
kind: "tool",
|
kind: "tool",
|
||||||
args: { tool_id: FactoryBot.create(:tool).id },
|
args: { tool_id: FactoryBot.create(:tool).id },
|
||||||
},
|
},
|
||||||
offset: {
|
offset: {
|
||||||
kind: "coordinate",
|
kind: "coordinate",
|
||||||
args: {
|
args: {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
"z": 0,
|
"z": 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
speed: 100,
|
speed: 100,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
check2 = CeleryScript::Checker.new(ok2, corpus, device)
|
check2 = CeleryScript::Checker.new(ok2, corpus, device)
|
||||||
expect(check2.valid?).to be_truthy
|
expect(check2.valid?).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it "kicks back invalid move_absolute nodes" do
|
it "kicks back invalid move_absolute nodes" do
|
||||||
bad = CeleryScript::AstNode.new(**{
|
bad = CeleryScript::AstNode.new(**{
|
||||||
kind: "move_absolute",
|
kind: "move_absolute",
|
||||||
args: {
|
args: {
|
||||||
location: 42,
|
location: 42,
|
||||||
speed: 100,
|
speed: 100,
|
||||||
offset: {
|
offset: {
|
||||||
kind: "coordinate",
|
kind: "coordinate",
|
||||||
args: {
|
args: {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
"z": 0,
|
"z": 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||||
expect(check.valid?).to be_falsey
|
expect(check.valid?).to be_falsey
|
||||||
expect(check.error.message).to include("but got Integer")
|
expect(check.error.message).to include("but got Integer")
|
||||||
|
@ -76,19 +76,19 @@ describe CeleryScript::Corpus do
|
||||||
|
|
||||||
it "finds problems with nested nodes" do
|
it "finds problems with nested nodes" do
|
||||||
bad = CeleryScript::AstNode.new(**{
|
bad = CeleryScript::AstNode.new(**{
|
||||||
kind: "move_absolute",
|
kind: "move_absolute",
|
||||||
args: {
|
args: {
|
||||||
location: {
|
location: {
|
||||||
kind: "tool",
|
kind: "tool",
|
||||||
args: { tool_id: "PROBLEM!" }, # <= Invalid:
|
args: { tool_id: "PROBLEM!" }, # <= Invalid:
|
||||||
},
|
},
|
||||||
offset: {
|
offset: {
|
||||||
kind: "coordinate",
|
kind: "coordinate",
|
||||||
args: { "x": 0, "y": 0, "z": 0 },
|
args: { "x": 0, "y": 0, "z": 0 },
|
||||||
},
|
},
|
||||||
speed: 100,
|
speed: 100,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||||
expect(check.valid?).to be_falsey
|
expect(check.valid?).to be_falsey
|
||||||
expect(check.error.message).to include("but got String")
|
expect(check.error.message).to include("but got String")
|
||||||
|
@ -110,31 +110,31 @@ describe CeleryScript::Corpus do
|
||||||
# This test is __ONLY__ relevant for version 1.
|
# This test is __ONLY__ relevant for version 1.
|
||||||
# Change / delete / update as needed.
|
# Change / delete / update as needed.
|
||||||
tree = CeleryScript::AstNode.new(**{
|
tree = CeleryScript::AstNode.new(**{
|
||||||
"kind": "send_message",
|
"kind": "send_message",
|
||||||
"args": {
|
"args": {
|
||||||
"message": "Hello, world!",
|
"message": "Hello, world!",
|
||||||
"message_type": "wrong",
|
"message_type": "wrong",
|
||||||
},
|
},
|
||||||
"body": [],
|
"body": [],
|
||||||
})
|
})
|
||||||
checker = CeleryScript::Checker.new(tree, corpus, device)
|
checker = CeleryScript::Checker.new(tree, corpus, device)
|
||||||
expect(checker.error.message).to include("not a valid message_type")
|
expect(checker.error.message).to include("not a valid message_type")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "Handles channel_name validations" do
|
it "Handles channel_name validations" do
|
||||||
tree = CeleryScript::AstNode.new(**{
|
tree = CeleryScript::AstNode.new(**{
|
||||||
"kind": "send_message",
|
"kind": "send_message",
|
||||||
"args": {
|
"args": {
|
||||||
"message": "Hello, world!",
|
"message": "Hello, world!",
|
||||||
"message_type": "fun",
|
"message_type": "fun",
|
||||||
},
|
},
|
||||||
"body": [
|
"body": [
|
||||||
{
|
{
|
||||||
"kind": "channel",
|
"kind": "channel",
|
||||||
"args": { "channel_name": "wrong" },
|
"args": { "channel_name": "wrong" },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
checker = CeleryScript::Checker.new(tree, corpus, device)
|
checker = CeleryScript::Checker.new(tree, corpus, device)
|
||||||
expect(checker.error.message).to include("not a valid channel_name")
|
expect(checker.error.message).to include("not a valid channel_name")
|
||||||
end
|
end
|
||||||
|
@ -150,10 +150,10 @@ describe CeleryScript::Corpus do
|
||||||
|
|
||||||
it "Validates resource_update nodes" do
|
it "Validates resource_update nodes" do
|
||||||
ast = { "kind": "resource_update",
|
ast = { "kind": "resource_update",
|
||||||
"args": { "resource_type" => "Device",
|
"args": { "resource_type" => "Device",
|
||||||
"resource_id" => 23, # Mutated to "0" later..
|
"resource_id" => 23, # Mutated to "0" later..
|
||||||
"label" => "mounted_tool_id",
|
"label" => "mounted_tool_id",
|
||||||
"value" => 1 } }
|
"value" => 1 } }
|
||||||
checker = CeleryScript::Checker
|
checker = CeleryScript::Checker
|
||||||
.new(CeleryScript::AstNode.new(**ast), corpus, device)
|
.new(CeleryScript::AstNode.new(**ast), corpus, device)
|
||||||
expect(checker.valid?).to be(true)
|
expect(checker.valid?).to be(true)
|
||||||
|
@ -164,10 +164,10 @@ describe CeleryScript::Corpus do
|
||||||
fake_id = FactoryBot.create(:plant).id + 1
|
fake_id = FactoryBot.create(:plant).id + 1
|
||||||
expect(Plant.exists?(fake_id)).to be(false)
|
expect(Plant.exists?(fake_id)).to be(false)
|
||||||
ast = { "kind": "resource_update",
|
ast = { "kind": "resource_update",
|
||||||
"args": { "resource_type" => "Plant",
|
"args": { "resource_type" => "Plant",
|
||||||
"resource_id" => fake_id,
|
"resource_id" => fake_id,
|
||||||
"label" => "foo",
|
"label" => "foo",
|
||||||
"value" => "Should Fail" } }
|
"value" => "Should Fail" } }
|
||||||
hmm = CeleryScript::AstNode.new(**ast)
|
hmm = CeleryScript::AstNode.new(**ast)
|
||||||
expect(hmm.args.fetch(:resource_id).value).to eq(fake_id)
|
expect(hmm.args.fetch(:resource_id).value).to eq(fake_id)
|
||||||
checker = CeleryScript::Checker.new(hmm, corpus, device)
|
checker = CeleryScript::Checker.new(hmm, corpus, device)
|
||||||
|
@ -177,10 +177,10 @@ describe CeleryScript::Corpus do
|
||||||
|
|
||||||
it "rejects bogus resource_types" do
|
it "rejects bogus resource_types" do
|
||||||
ast = { "kind": "resource_update",
|
ast = { "kind": "resource_update",
|
||||||
"args": { "resource_type" => "CanOpener",
|
"args": { "resource_type" => "CanOpener",
|
||||||
"resource_id" => 0,
|
"resource_id" => 0,
|
||||||
"label" => "foo",
|
"label" => "foo",
|
||||||
"value" => "Should Fail" } }
|
"value" => "Should Fail" } }
|
||||||
checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(**ast),
|
checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(**ast),
|
||||||
corpus,
|
corpus,
|
||||||
device)
|
device)
|
||||||
|
@ -224,9 +224,9 @@ describe CeleryScript::Corpus do
|
||||||
|
|
||||||
it "sets a MAX_WAIT_MS limit for `wait` nodes" do
|
it "sets a MAX_WAIT_MS limit for `wait` nodes" do
|
||||||
bad = CeleryScript::AstNode.new(**{
|
bad = CeleryScript::AstNode.new(**{
|
||||||
kind: "wait",
|
kind: "wait",
|
||||||
args: { milliseconds: CeleryScriptSettingsBag::MAX_WAIT_MS + 10 },
|
args: { milliseconds: CeleryScriptSettingsBag::MAX_WAIT_MS + 10 },
|
||||||
})
|
})
|
||||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||||
expect(check.valid?).to be_falsey
|
expect(check.valid?).to be_falsey
|
||||||
expect(check.error.message).to include("cannot exceed 3 minutes")
|
expect(check.error.message).to include("cannot exceed 3 minutes")
|
||||||
|
@ -238,9 +238,9 @@ describe CeleryScript::Corpus do
|
||||||
name: "cs checks",
|
name: "cs checks",
|
||||||
point_ids: [])
|
point_ids: [])
|
||||||
bad = CeleryScript::AstNode.new(**{
|
bad = CeleryScript::AstNode.new(**{
|
||||||
kind: "point_group",
|
kind: "point_group",
|
||||||
args: { point_group_id: pg.id },
|
args: { point_group_id: pg.id },
|
||||||
})
|
})
|
||||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||||
expect(check.valid?).to be true
|
expect(check.valid?).to be true
|
||||||
end
|
end
|
||||||
|
@ -249,12 +249,35 @@ describe CeleryScript::Corpus do
|
||||||
it "disallows invalid `point_group` nodes" do
|
it "disallows invalid `point_group` nodes" do
|
||||||
device.auto_sync_transaction do
|
device.auto_sync_transaction do
|
||||||
bad = CeleryScript::AstNode.new(**{
|
bad = CeleryScript::AstNode.new(**{
|
||||||
kind: "point_group",
|
kind: "point_group",
|
||||||
args: { point_group_id: -1 },
|
args: { point_group_id: -1 },
|
||||||
})
|
})
|
||||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||||
expect(check.valid?).to be false
|
expect(check.valid?).to be false
|
||||||
expect(check.error.message).to eq("Can't find PointGroup with id of -1")
|
expect(check.error.message).to eq("Can't find PointGroup with id of -1")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "validates the `package` for flash_firmware" do
|
||||||
|
ok1 = CeleryScript::AstNode.new(**{
|
||||||
|
args: {
|
||||||
|
version: 20180209,
|
||||||
|
locals: {
|
||||||
|
kind: "scope_declaration",
|
||||||
|
args: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
kind: "sequence",
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
kind: "flash_firmware",
|
||||||
|
args: {
|
||||||
|
package: "arduino_firmware",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
check1 = CeleryScript::Checker.new(ok1, corpus, device)
|
||||||
|
expect(check1.valid?).to be_truthy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue