• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

asciimoth / pasta / 26626415405

29 May 2026 08:18AM UTC coverage: 77.855% (-0.3%) from 78.117%
26626415405

push

github

asciimoth
fix(std): fix formular menu handling by some nodes

20 of 72 new or added lines in 12 files covered. (27.78%)

1 existing line in 1 file now uncovered.

5467 of 7022 relevant lines covered (77.86%)

323.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.1
/pasta/std/node_string_constant.go
1
package std
2

3
import (
4
        "github.com/asciimoth/configer/configer"
5
        "github.com/asciimoth/formular"
6
        "github.com/asciimoth/pasta/pasta"
7
)
8

9
// NodeTypeStringConstant is the class name for StringConstantClass.
10
const NodeTypeStringConstant = "pasta/StringConstant"
11

12
// StringConstantClass creates nodes with one editable string value and one
13
// right-directed pasta/string output port.
14
type StringConstantClass struct{}
15

16
func (StringConstantClass) ClassName() string        { return NodeTypeStringConstant }
198✔
17
func (StringConstantClass) ShortDescription() string { return "String constant" }
179✔
18
func (StringConstantClass) LongDescription() string {
×
19
        return "Outputs an editable string value on one pasta/string right-directed port. The label and menu field always show the current value."
×
20
}
×
21
func (StringConstantClass) DefaultNodeParams() pasta.NodeClassParams {
233✔
22
        return pasta.NodeClassParams{PrimaryType: TypeString, InitialPorts: []pasta.Port{rightPort(TypeString)}}
233✔
23
}
233✔
24
func (StringConstantClass) NewNode(cfg configer.Config, _ ...*pasta.NodeClassState) (pasta.Node, error) {
12✔
25
        return newStringConstantNode(readString(cfg, "")), nil
12✔
26
}
12✔
27

28
type stringConstantNode struct {
29
        pasta.BasicNode
30

31
        value string
32
        w     *pasta.Workspace
33
        id    uint64
34
        out   uint64
35
}
36

37
func newStringConstantNode(value string) *stringConstantNode {
12✔
38
        return &stringConstantNode{value: value}
12✔
39
}
12✔
40

41
func (n *stringConstantNode) OnInit(w *pasta.Workspace, _ pasta.Logger, id uint64, _ string, restored *pasta.NodeInitData, _, _, _, _ bool) error {
12✔
42
        n.w = w
12✔
43
        n.id = id
12✔
44
        if restored != nil && len(restored.RightPorts) > 0 {
24✔
45
                n.out = restored.RightPorts[0]
12✔
46
        }
12✔
47
        if err := n.w.SetNodePrimary(n.id, TypeString); err != nil {
12✔
48
                return err
×
49
        }
×
50
        if err := n.updateLabel(); err != nil {
12✔
51
                return err
×
52
        }
×
53
        n.sendMenuSnapshot()
12✔
54
        return nil
12✔
55
}
56

57
func (n *stringConstantNode) OnReady() error {
12✔
58
        n.sendAll()
12✔
59
        return nil
12✔
60
}
12✔
61

62
func (n *stringConstantNode) PreLinkAdd(port uint64, linkType, _ string) error {
15✔
63
        if port != n.out || linkType != TypeString {
15✔
NEW
64
                return pasta.LinkTypeErr(linkType)
×
65
        }
×
66
        return nil
15✔
67
}
68

69
func (n *stringConstantNode) OnLinkAdd(link, port uint64, _, _ string) error {
15✔
70
        if port == n.out {
30✔
71
                n.sendToLink(link)
15✔
72
        }
15✔
73
        return nil
15✔
74
}
75

76
func (n *stringConstantNode) OnEvent(event pasta.Event, linkType string, _ []string, receiverPortDirection string) error {
19✔
77
        if event.ReceiverPort != n.out || receiverPortDirection != "right" || linkType != TypeString || !isValueRequest(event.Payload) {
19✔
78
                return nil
×
79
        }
×
80
        n.w.SendEvent(pasta.Event{SenderNode: n.id, SenderPort: n.out, ReceiverNode: event.SenderNode, ReceiverPort: event.SenderPort, Payload: String(n.value)})
19✔
81
        return nil
19✔
82
}
83

84
func (n *stringConstantNode) OnFormularMsg(message any) error {
9✔
85
        msg, ok := message.(formular.FieldUpdateMessage)
9✔
86
        if !ok || msg.MenuID != pasta.NodeMenuID(n.id) || msg.Field.BlockID != "state" || msg.Field.FieldID != "value" {
9✔
87
                return nil
×
88
        }
×
89
        next, ok := parseStringAny(msg.Value)
9✔
90
        if !ok || next == n.value {
9✔
91
                return nil
×
92
        }
×
93
        n.value = next
9✔
94
        if err := n.updateLabel(); err != nil {
9✔
95
                return err
×
96
        }
×
97
        n.sendMenuBlock()
9✔
98
        n.sendAll()
9✔
99
        return nil
9✔
100
}
101

102
func (n *stringConstantNode) OnSave(cfg configer.Config) error {
4✔
103
        if err := pasta.DeleteNodeOwnedConfigKeys(cfg); err != nil {
4✔
104
                return err
×
105
        }
×
106
        return cfg.Set(configer.Path{"value"}, n.value)
4✔
107
}
108

109
func (n *stringConstantNode) updateLabel() error {
21✔
110
        return n.w.SetNodeLabel(n.id, n.value)
21✔
111
}
21✔
112

113
func (n *stringConstantNode) sendAll() {
21✔
114
        port, ok := n.w.PortSnapshot(n.out)
21✔
115
        if !ok {
21✔
116
                return
×
117
        }
×
118
        for _, link := range port.Links {
26✔
119
                n.sendToLink(link)
5✔
120
        }
5✔
121
}
122

123
func (n *stringConstantNode) sendToLink(link uint64) {
20✔
124
        snapshot, ok := n.w.LinkSnapshot(link)
20✔
125
        if !ok {
20✔
126
                return
×
127
        }
×
128
        receiverNode, receiverPort := otherEndpoint(snapshot, n.out)
20✔
129
        n.w.SendEvent(pasta.Event{SenderNode: n.id, SenderPort: n.out, ReceiverNode: receiverNode, ReceiverPort: receiverPort, Payload: String(n.value)})
20✔
130
}
131

132
func (n *stringConstantNode) sendMenuSnapshot() {
12✔
133
        n.w.SendNodeMenuMsg(n.id, formular.MenuSnapshotMessage{
12✔
134
                MessageBase: formular.MessageBase{Type: formular.MessageMenuSnapshot, MenuID: pasta.NodeMenuID(n.id), MenuGeneration: 1},
12✔
135
                Blocks:      []formular.Block{n.menuBlock()},
12✔
136
        })
12✔
137
}
12✔
138

139
func (n *stringConstantNode) sendMenuBlock() {
9✔
140
        n.w.SendNodeMenuMsg(n.id, formular.BlockSnapshotMessage{
9✔
141
                MessageBase: formular.MessageBase{Type: formular.MessageBlockSnapshot, MenuID: pasta.NodeMenuID(n.id), MenuGeneration: 1, BlockGeneration: 1},
9✔
142
                Block:       n.menuBlock(),
9✔
143
        })
9✔
144
}
9✔
145

146
func (n *stringConstantNode) menuBlock() formular.Block {
21✔
147
        return formular.Block{
21✔
148
                ID: "state", Order: 10, Generation: 1,
21✔
149
                Items: []formular.Item{{Type: formular.ItemField, ID: "value", Label: "Value", Field: &formular.Field{Kind: formular.FieldText, Value: n.value}}},
21✔
150
        }
21✔
151
}
21✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc