Compare commits

...

8 Commits
jebba ... hmm

Author SHA1 Message Date
Rick Carlino be38ad830a Merge branch 'master' of https://git.heroku.com/farmbot-staging into staging 2020-03-17 14:44:54 -05:00
Rick Carlino 4f03626d5f Merge branch 'master' into staging 2020-03-17 14:43:25 -05:00
Rick Carlino bc68f3e79f Merge branch 'staging' 2020-03-16 19:08:55 -05:00
Rick Carlino bce0700cd9
Merge pull request #1723 from FarmBot/staging
v9.2.0 - Jolly Juniper
2020-02-27 15:37:03 -06:00
Rick Carlino 9f1cf4eedd Loosen restriction on `package` attr of `flash_firmware`. 2020-02-20 18:13:46 -06:00
Rick Carlino afceaf25e0 Add test for flash_firmware node 2020-02-20 18:03:23 -06:00
Rick Carlino e5389b747e Begin work on 'flash firmware' button 2020-02-20 17:32:58 -06:00
Rick Carlino a5b1d5631e
Merge pull request #1701 from FarmBot/staging
v9.1.3 - Jolly Juniper
2020-02-20 12:57:33 -06:00
4 changed files with 140 additions and 115 deletions

View File

@ -16,9 +16,9 @@ module CeleryScriptSettingsBag
end
PIN_TYPE_MAP = { "Peripheral" => Peripheral,
"Sensor" => Sensor,
"BoxLed3" => BoxLed,
"BoxLed4" => BoxLed }
"Sensor" => Sensor,
"BoxLed3" => BoxLed,
"BoxLed4" => BoxLed }
ALLOWED_AXIS = %w(x y z all)
ALLOWED_ASSERTION_TYPES = %w(abort recover abort_recover continue)
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
# than a string), it would cause false type errors in FE/FBJS.
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,
},
axis: {
@ -529,7 +531,7 @@ module CeleryScriptSettingsBag
resource_id = n.args.fetch(:point_group_id).value
check_resource_type(n, "PointGroup", resource_id, Device.current)
end,
}
},
}.map { |(name, list)| Corpus.node(name, **list) }
HASH = Corpus.as_json

View File

@ -95,6 +95,11 @@ export function StepButtonCluster(props: StepButtonProps) {
color="brown">
{t("REBOOT")}
</StepButton>,
<StepButton {...commonStepProps}
step={{ kind: "flash_firmware", args: { package: "arduino_firmware" } }}
color="brown">
{t("REFLASH FIRMWARE")}
</StepButton>,
<StepButton {...commonStepProps}
step={{ kind: "emergency_lock", args: {} }}
color="red">

View File

@ -5,11 +5,6 @@ import { StepWrapper, StepHeader, StepContent } from "../step_ui/index";
import { t } from "../../i18next_wrapper";
import { ALLOWED_PACKAGES, SequenceBodyItem, Reboot } from "farmbot";
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 {
if (x.kind !== "reboot") {

View File

@ -6,68 +6,68 @@ describe CeleryScript::Corpus do
it "handles valid move_absolute blocks" do
ok1 = CeleryScript::AstNode.new(**{
kind: "move_absolute",
args: {
location: {
kind: "coordinate",
args: {
x: 1,
y: 2,
z: 3,
},
},
offset: {
kind: "coordinate",
args: {
"x": 0,
"y": 0,
"z": 0,
},
},
speed: 100,
},
})
kind: "move_absolute",
args: {
location: {
kind: "coordinate",
args: {
x: 1,
y: 2,
z: 3,
},
},
offset: {
kind: "coordinate",
args: {
"x": 0,
"y": 0,
"z": 0,
},
},
speed: 100,
},
})
check1 = CeleryScript::Checker.new(ok1, corpus, device)
expect(check1.valid?).to be_truthy
ok2 = CeleryScript::AstNode.new(**{
kind: "move_absolute",
args: {
location: {
kind: "tool",
args: { tool_id: FactoryBot.create(:tool).id },
},
offset: {
kind: "coordinate",
args: {
"x": 0,
"y": 0,
"z": 0,
},
},
speed: 100,
},
})
kind: "move_absolute",
args: {
location: {
kind: "tool",
args: { tool_id: FactoryBot.create(:tool).id },
},
offset: {
kind: "coordinate",
args: {
"x": 0,
"y": 0,
"z": 0,
},
},
speed: 100,
},
})
check2 = CeleryScript::Checker.new(ok2, corpus, device)
expect(check2.valid?).to be_truthy
end
it "kicks back invalid move_absolute nodes" do
bad = CeleryScript::AstNode.new(**{
kind: "move_absolute",
args: {
location: 42,
speed: 100,
offset: {
kind: "coordinate",
args: {
"x": 0,
"y": 0,
"z": 0,
},
},
},
})
kind: "move_absolute",
args: {
location: 42,
speed: 100,
offset: {
kind: "coordinate",
args: {
"x": 0,
"y": 0,
"z": 0,
},
},
},
})
check = CeleryScript::Checker.new(bad, corpus, device)
expect(check.valid?).to be_falsey
expect(check.error.message).to include("but got Integer")
@ -76,19 +76,19 @@ describe CeleryScript::Corpus do
it "finds problems with nested nodes" do
bad = CeleryScript::AstNode.new(**{
kind: "move_absolute",
args: {
location: {
kind: "tool",
args: { tool_id: "PROBLEM!" }, # <= Invalid:
},
offset: {
kind: "coordinate",
args: { "x": 0, "y": 0, "z": 0 },
},
speed: 100,
},
})
kind: "move_absolute",
args: {
location: {
kind: "tool",
args: { tool_id: "PROBLEM!" }, # <= Invalid:
},
offset: {
kind: "coordinate",
args: { "x": 0, "y": 0, "z": 0 },
},
speed: 100,
},
})
check = CeleryScript::Checker.new(bad, corpus, device)
expect(check.valid?).to be_falsey
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.
# Change / delete / update as needed.
tree = CeleryScript::AstNode.new(**{
"kind": "send_message",
"args": {
"message": "Hello, world!",
"message_type": "wrong",
},
"body": [],
})
"kind": "send_message",
"args": {
"message": "Hello, world!",
"message_type": "wrong",
},
"body": [],
})
checker = CeleryScript::Checker.new(tree, corpus, device)
expect(checker.error.message).to include("not a valid message_type")
end
it "Handles channel_name validations" do
tree = CeleryScript::AstNode.new(**{
"kind": "send_message",
"args": {
"message": "Hello, world!",
"message_type": "fun",
},
"body": [
{
"kind": "channel",
"args": { "channel_name": "wrong" },
},
],
})
"kind": "send_message",
"args": {
"message": "Hello, world!",
"message_type": "fun",
},
"body": [
{
"kind": "channel",
"args": { "channel_name": "wrong" },
},
],
})
checker = CeleryScript::Checker.new(tree, corpus, device)
expect(checker.error.message).to include("not a valid channel_name")
end
@ -150,10 +150,10 @@ describe CeleryScript::Corpus do
it "Validates resource_update nodes" do
ast = { "kind": "resource_update",
"args": { "resource_type" => "Device",
"resource_id" => 23, # Mutated to "0" later..
"label" => "mounted_tool_id",
"value" => 1 } }
"args": { "resource_type" => "Device",
"resource_id" => 23, # Mutated to "0" later..
"label" => "mounted_tool_id",
"value" => 1 } }
checker = CeleryScript::Checker
.new(CeleryScript::AstNode.new(**ast), corpus, device)
expect(checker.valid?).to be(true)
@ -164,10 +164,10 @@ describe CeleryScript::Corpus do
fake_id = FactoryBot.create(:plant).id + 1
expect(Plant.exists?(fake_id)).to be(false)
ast = { "kind": "resource_update",
"args": { "resource_type" => "Plant",
"resource_id" => fake_id,
"label" => "foo",
"value" => "Should Fail" } }
"args": { "resource_type" => "Plant",
"resource_id" => fake_id,
"label" => "foo",
"value" => "Should Fail" } }
hmm = CeleryScript::AstNode.new(**ast)
expect(hmm.args.fetch(:resource_id).value).to eq(fake_id)
checker = CeleryScript::Checker.new(hmm, corpus, device)
@ -177,10 +177,10 @@ describe CeleryScript::Corpus do
it "rejects bogus resource_types" do
ast = { "kind": "resource_update",
"args": { "resource_type" => "CanOpener",
"resource_id" => 0,
"label" => "foo",
"value" => "Should Fail" } }
"args": { "resource_type" => "CanOpener",
"resource_id" => 0,
"label" => "foo",
"value" => "Should Fail" } }
checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(**ast),
corpus,
device)
@ -224,9 +224,9 @@ describe CeleryScript::Corpus do
it "sets a MAX_WAIT_MS limit for `wait` nodes" do
bad = CeleryScript::AstNode.new(**{
kind: "wait",
args: { milliseconds: CeleryScriptSettingsBag::MAX_WAIT_MS + 10 },
})
kind: "wait",
args: { milliseconds: CeleryScriptSettingsBag::MAX_WAIT_MS + 10 },
})
check = CeleryScript::Checker.new(bad, corpus, device)
expect(check.valid?).to be_falsey
expect(check.error.message).to include("cannot exceed 3 minutes")
@ -238,9 +238,9 @@ describe CeleryScript::Corpus do
name: "cs checks",
point_ids: [])
bad = CeleryScript::AstNode.new(**{
kind: "point_group",
args: { point_group_id: pg.id },
})
kind: "point_group",
args: { point_group_id: pg.id },
})
check = CeleryScript::Checker.new(bad, corpus, device)
expect(check.valid?).to be true
end
@ -249,12 +249,35 @@ describe CeleryScript::Corpus do
it "disallows invalid `point_group` nodes" do
device.auto_sync_transaction do
bad = CeleryScript::AstNode.new(**{
kind: "point_group",
args: { point_group_id: -1 },
})
kind: "point_group",
args: { point_group_id: -1 },
})
check = CeleryScript::Checker.new(bad, corpus, device)
expect(check.valid?).to be false
expect(check.error.message).to eq("Can't find PointGroup with id of -1")
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