gdp-wired 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +8 -2
- package/dist/core/data.js +1113 -172
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +18 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
package/dist/core/py/harness.py
CHANGED
|
@@ -9,10 +9,19 @@ import time as time_module
|
|
|
9
9
|
|
|
10
10
|
NOW = [0]
|
|
11
11
|
CUR = {}
|
|
12
|
+
EFF = {}
|
|
12
13
|
HIT = set()
|
|
13
14
|
S = {}
|
|
14
15
|
|
|
16
|
+
def datetime_in(v, unit):
|
|
17
|
+
epoch = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc if unit == 'datetime-utc' else None)
|
|
18
|
+
return epoch + datetime.timedelta(milliseconds=int(v))
|
|
19
|
+
|
|
15
20
|
def enc_num(v):
|
|
21
|
+
if isinstance(v, datetime.datetime):
|
|
22
|
+
epoch = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc if v.tzinfo is not None else None)
|
|
23
|
+
delta = v - epoch
|
|
24
|
+
return str(delta.days * 86400000 + delta.seconds * 1000 + delta.microseconds // 1000) if delta.microseconds % 1000 == 0 else '?:sub-millisecond datetime'
|
|
16
25
|
if isinstance(v, bool): return v
|
|
17
26
|
if isinstance(v, int): return str(v)
|
|
18
27
|
if isinstance(v, float):
|
|
@@ -38,6 +47,13 @@ def resolve(q):
|
|
|
38
47
|
mod, _, name = q.rpartition('.')
|
|
39
48
|
return getattr(importlib.import_module(mod), name)
|
|
40
49
|
|
|
50
|
+
class Inert:
|
|
51
|
+
"""An attribute of a store the rule leaves out (a registry the constructor adds to): its calls do nothing."""
|
|
52
|
+
def __getattr__(self, name):
|
|
53
|
+
if name.startswith('__'): raise AttributeError(name)
|
|
54
|
+
return Inert()
|
|
55
|
+
def __call__(self, *a, **k): return None
|
|
56
|
+
|
|
41
57
|
class FakeStore:
|
|
42
58
|
"""A store as the caller stated it: get, set and delete over a dict that keeps what is set (no expiry)."""
|
|
43
59
|
def __init__(self, decl, name=None):
|
|
@@ -45,9 +61,17 @@ class FakeStore:
|
|
|
45
61
|
for path, v in (decl.get('attrs') or {}).items():
|
|
46
62
|
o, parts = self, path.split('.')
|
|
47
63
|
for p in parts[:-1]:
|
|
48
|
-
if not
|
|
64
|
+
if p not in vars(o): setattr(o, p, types.SimpleNamespace())
|
|
49
65
|
o = getattr(o, p)
|
|
50
66
|
setattr(o, parts[-1], v)
|
|
67
|
+
# (an attribute the rule leaves out, a registry the constructor adds to: inert, its calls doing nothing)
|
|
68
|
+
for i in S.get('inert') or []:
|
|
69
|
+
if i['store'] != name: continue
|
|
70
|
+
o, parts = self, i['path'].split('.')
|
|
71
|
+
for p in parts[:-1]:
|
|
72
|
+
if p not in vars(o): setattr(o, p, types.SimpleNamespace())
|
|
73
|
+
o = getattr(o, p)
|
|
74
|
+
if parts[-1] not in vars(o): setattr(o, parts[-1], Inert())
|
|
51
75
|
asyncs = decl.get('async') or {}
|
|
52
76
|
def mk(kind, name):
|
|
53
77
|
# (the key by position, or as key= or name=, redis-py's; nx and xx as redis-py's: True where it set, else None)
|
|
@@ -59,7 +83,16 @@ class FakeStore:
|
|
|
59
83
|
self.data[key] = val
|
|
60
84
|
if k.get('nx') or k.get('xx'): return True
|
|
61
85
|
def delete(*a, **k): self.data.pop(kk(a, k), None)
|
|
62
|
-
|
|
86
|
+
# (add: set where the key holds nothing, True where it set; incr: by amount, absent as 0, the new number)
|
|
87
|
+
def add(*a, **k):
|
|
88
|
+
key = kk(a, k)
|
|
89
|
+
if key in self.data: return False
|
|
90
|
+
self.data[key] = k.get('value', a[1] if len(a) > 1 else None)
|
|
91
|
+
return True
|
|
92
|
+
def incr(*a, **k):
|
|
93
|
+
key = kk(a, k); self.data[key] = (self.data.get(key) or 0) + k.get('amount', a[1] if len(a) > 1 else 1)
|
|
94
|
+
return self.data[key]
|
|
95
|
+
f0, key = {'get': get, 'set': set_, 'delete': delete, 'add': add, 'incr': incr}[kind], f"{self.name}.{name}"
|
|
63
96
|
# (where the request says the operation raises, inside a try that catches it)
|
|
64
97
|
def f(*a, **k):
|
|
65
98
|
r = (CUR.get(key) or {}).get('raise')
|
|
@@ -69,24 +102,165 @@ class FakeStore:
|
|
|
69
102
|
async def af(*a, **k): return f(*a, **k)
|
|
70
103
|
return af
|
|
71
104
|
return f
|
|
72
|
-
|
|
73
|
-
|
|
105
|
+
own = set()
|
|
106
|
+
for kind, dflt in (('get', ['get', 'async_get_cache', 'get_cache']), ('set', ['set', 'async_set_cache', 'set_cache']), ('delete', ['delete', 'delete_cache', 'async_delete_cache']), ('add', []), ('incr', [])):
|
|
107
|
+
for m in decl.get(kind) or dflt: setattr(self, m, mk(kind, m)); own.add(m)
|
|
74
108
|
# (a method left out: nothing, as the rule takes it; any other is no method of this store, and fails)
|
|
75
109
|
for m in decl.get('skip') or []:
|
|
76
110
|
async def anop(*a, **k): return None
|
|
77
111
|
setattr(self, m, (lambda *a, **k: anop()) if asyncs.get(m) else (lambda *a, **k: None))
|
|
78
|
-
# (an injected dependency's other methods: each answered by the request's input
|
|
112
|
+
# (an injected dependency's other methods: each answered by the request's input; one left out does nothing, and
|
|
113
|
+
# raises where the request says, as its get, set and delete do)
|
|
79
114
|
for a in S.get('answers') or []:
|
|
80
|
-
if a['patch'].get('store')
|
|
115
|
+
if a['patch'].get('store') != name: continue
|
|
116
|
+
if not a['patch'].get('path'):
|
|
117
|
+
if os.environ.get('GDP_HARNESS_LOG'):
|
|
118
|
+
with open(os.environ['GDP_HARNESS_LOG'], 'a') as f: f.write(f"a store's answer with no method: {json.dumps(a)[:400]}\n")
|
|
119
|
+
continue
|
|
120
|
+
m = a['patch']['path'][-1]
|
|
121
|
+
if a['patch'].get('store') == name and a.get('effect'):
|
|
122
|
+
def rec(key, is_async):
|
|
123
|
+
def f(*x, **k): EFF[key] = True
|
|
124
|
+
async def af(*x, **k): EFF[key] = True
|
|
125
|
+
return af if is_async else f
|
|
126
|
+
setattr(self, m, rec(a['key'], a['async']))
|
|
127
|
+
elif a['patch'].get('store') == name and not (a.get('pass') and m in own): setattr(self, m, stub(a['key'], a['async'], (lambda *x, **k: None) if a.get('pass') else None))
|
|
128
|
+
|
|
129
|
+
ORM_VALIDATED = set()
|
|
130
|
+
|
|
131
|
+
class ORMTable:
|
|
132
|
+
"""Only the persistence boundary is faked; methods execute on the real model class.
|
|
133
|
+
Reads detach copies, and save snapshots a row. No schema or database is created.
|
|
134
|
+
"""
|
|
135
|
+
def __init__(self, leaf):
|
|
136
|
+
self.leaf, self.meta, self.data = leaf, leaf['orm'], {}
|
|
137
|
+
self.cls = resolve(self.meta['rec'])
|
|
138
|
+
self.key = self.meta['key']
|
|
139
|
+
if self.cls not in ORM_VALIDATED:
|
|
140
|
+
access = {'__getattribute__', '__getattr__', '__setattr__', '__delattr__'}
|
|
141
|
+
if self.meta['framework'] == 'django':
|
|
142
|
+
from django.db.models import Model, Manager
|
|
143
|
+
# Display methods are retained, never replaced by persistence stubs. The
|
|
144
|
+
# reader refuses implicit object display, including discarded results.
|
|
145
|
+
methods = ({n for n, v in vars(Model).items() if inspect.isfunction(v) or isinstance(v, (staticmethod, classmethod, property))} - {'__str__', '__repr__'}) | access
|
|
146
|
+
unsafe = any(inspect.getattr_static(self.cls, n, None) is not inspect.getattr_static(Model, n, None) for n in methods) or type(self.cls.objects) is not Manager
|
|
147
|
+
else:
|
|
148
|
+
from sqlalchemy.orm.decl_base import _declarative_constructor
|
|
149
|
+
manager = self.cls._sa_class_manager
|
|
150
|
+
unsafe = manager.original_init is not _declarative_constructor or self.cls.__init__ is not manager.new_init or any(inspect.getattr_static(self.cls, n, None) is not inspect.getattr_static(object, n, None) for n in access)
|
|
151
|
+
if unsafe: raise ValueError('custom or inherited ORM persistence behavior is outside the table boundary')
|
|
152
|
+
ORM_VALIDATED.add(self.cls)
|
|
153
|
+
def install(self):
|
|
154
|
+
if self.meta['framework'] == 'django': self.cls.objects = self
|
|
155
|
+
table = self
|
|
156
|
+
def save(row, *args, **kw):
|
|
157
|
+
if args or kw: raise ValueError('ORM save options outside boundary')
|
|
158
|
+
table.data[getattr(row, table.key)] = {f['name']: getattr(row, f['name']) for f in table.meta['fields']}
|
|
159
|
+
def delete(row, *args, **kw):
|
|
160
|
+
if args or kw: raise ValueError('ORM delete options outside boundary')
|
|
161
|
+
key = getattr(row, table.key)
|
|
162
|
+
n = int(key in table.data)
|
|
163
|
+
table.data.pop(key, None)
|
|
164
|
+
setattr(row, table.key, None)
|
|
165
|
+
return n, {table.cls._meta.label: n}
|
|
166
|
+
self.cls.save = save
|
|
167
|
+
self.cls.delete = delete
|
|
168
|
+
def lookup(self, kw):
|
|
169
|
+
if len(kw) != 1: raise ValueError('one primary key required')
|
|
170
|
+
name, value = next(iter(kw.items()))
|
|
171
|
+
if name not in ('pk', self.key): raise ValueError('non-key filter')
|
|
172
|
+
return value
|
|
173
|
+
def get(self, **kw):
|
|
174
|
+
key = self.lookup(kw)
|
|
175
|
+
if key not in self.data: raise self.cls.DoesNotExist()
|
|
176
|
+
return self.cls(**self.data[key])
|
|
177
|
+
def create(self, **kw):
|
|
178
|
+
from django.db import IntegrityError
|
|
179
|
+
key = kw[self.key]
|
|
180
|
+
if key in self.data: raise IntegrityError('duplicate primary key')
|
|
181
|
+
row = self.cls(**kw)
|
|
182
|
+
row.save()
|
|
183
|
+
return row
|
|
184
|
+
def filter(self, **kw):
|
|
185
|
+
table, key = self, self.lookup(kw)
|
|
186
|
+
class Query:
|
|
187
|
+
def exists(self): return key in table.data
|
|
188
|
+
def first(self): return table.cls(**table.data[key]) if key in table.data else None
|
|
189
|
+
def delete(self):
|
|
190
|
+
n = int(key in table.data)
|
|
191
|
+
table.data.pop(key, None)
|
|
192
|
+
return n, {table.cls._meta.label: n}
|
|
193
|
+
return Query()
|
|
194
|
+
|
|
195
|
+
class ORMSession:
|
|
196
|
+
def __init__(self): self.loaded, self.added, self.data = [], [], {}
|
|
197
|
+
def table(self, cls):
|
|
198
|
+
return next(t for t in OBJ_STORES.values() if isinstance(t, ORMTable) and t.cls is cls)
|
|
199
|
+
def get(self, cls, key):
|
|
200
|
+
table = self.table(cls)
|
|
201
|
+
if key not in table.data: return None
|
|
202
|
+
row = cls(**table.data[key]); self.loaded.append((row, False))
|
|
203
|
+
return row
|
|
204
|
+
def add(self, row):
|
|
205
|
+
if any(r is row for r, _ in self.loaded): return
|
|
206
|
+
self.added.append(row)
|
|
207
|
+
self.loaded.append((row, False))
|
|
208
|
+
def delete(self, row):
|
|
209
|
+
self.loaded = [(r, d) for r, d in self.loaded if r is not row]
|
|
210
|
+
self.loaded.append((row, True))
|
|
211
|
+
def commit(self):
|
|
212
|
+
pending = set()
|
|
213
|
+
for row in self.added:
|
|
214
|
+
table = self.table(type(row)); key = getattr(row, table.key)
|
|
215
|
+
if key in table.data or (table, key) in pending: raise ValueError('duplicate primary key')
|
|
216
|
+
pending.add((table, key))
|
|
217
|
+
for row, deleted in self.loaded:
|
|
218
|
+
table = self.table(type(row))
|
|
219
|
+
if deleted: table.data.pop(getattr(row, table.key), None)
|
|
220
|
+
else: table.data[getattr(row, table.key)] = {f['name']: getattr(row, f['name']) for f in table.meta['fields']}
|
|
221
|
+
self.loaded.clear()
|
|
222
|
+
|
|
223
|
+
def orm_snapshot(table):
|
|
224
|
+
out = {}
|
|
225
|
+
for key, row in table.data.items():
|
|
226
|
+
cell = {}
|
|
227
|
+
for field in table.meta['fields']:
|
|
228
|
+
name, t = field['name'], field['t']
|
|
229
|
+
if name == table.key: continue
|
|
230
|
+
value = row[name]
|
|
231
|
+
if t['k'] == 'opt':
|
|
232
|
+
cell[name + '_has'] = value is not None
|
|
233
|
+
t = t['of']
|
|
234
|
+
if value is None: value = '' if t['k'] == 'str' else False if t['k'] == 'bool' else 0
|
|
235
|
+
cell[name] = value if t['k'] in ('str', 'bool', 'choice') else enc_num(value)
|
|
236
|
+
out[str(key)] = cell
|
|
237
|
+
return out
|
|
238
|
+
|
|
239
|
+
def orm_restore(table, cells):
|
|
240
|
+
table.data.clear()
|
|
241
|
+
for key, cell in cells.items():
|
|
242
|
+
key = int(key) if table.leaf['key'] == 'num' else key
|
|
243
|
+
row = {table.key: key}
|
|
244
|
+
for field in table.meta['fields']:
|
|
245
|
+
name, t = field['name'], field['t']
|
|
246
|
+
if name == table.key: continue
|
|
247
|
+
optional = t['k'] == 'opt'
|
|
248
|
+
if optional: t = t['of']
|
|
249
|
+
row[name] = None if optional and not cell[name + '_has'] else datetime_in(cell[name], t['unit']) if t.get('unit', '').startswith('datetime-') else int(cell[name]) if t['k'] == 'int' else cell[name]
|
|
250
|
+
table.data[key] = row
|
|
81
251
|
|
|
82
252
|
def build(spec, stores):
|
|
83
253
|
if 'in' in spec:
|
|
84
254
|
v = spec['in']
|
|
255
|
+
if spec.get('time'): return datetime_in(v, spec['time'])
|
|
85
256
|
if spec.get('bytes') and isinstance(v, str): return v.encode('latin-1')
|
|
86
257
|
return float(v) if spec.get('float') and isinstance(v, int) and not isinstance(v, bool) else v
|
|
87
258
|
if spec.get('none'): return None
|
|
88
259
|
if spec.get('inert'): return {} if spec.get('dict') else Inert()
|
|
89
|
-
if 'store' in spec:
|
|
260
|
+
if 'store' in spec:
|
|
261
|
+
name = spec['store']
|
|
262
|
+
if name not in stores: stores[name] = ORMSession() if S['stores'].get(name, {}).get('ormSession') else FakeStore(S['stores'].get(name, {}), name)
|
|
263
|
+
return stores[name]
|
|
90
264
|
if 'list' in spec: return [build(x, stores) for x in spec['list']]
|
|
91
265
|
if 'rec' in spec:
|
|
92
266
|
cls = resolve(spec['rec'])
|
|
@@ -154,6 +328,9 @@ def state_of(obj, stores):
|
|
|
154
328
|
for l in S['leaves']:
|
|
155
329
|
k = l['kind']
|
|
156
330
|
if k == 'frame': continue
|
|
331
|
+
if l.get('orm'):
|
|
332
|
+
s[l['name']] = orm_snapshot(stores[l['name']])
|
|
333
|
+
continue
|
|
157
334
|
if l.get('store'):
|
|
158
335
|
st = stores.get(l['store'])
|
|
159
336
|
cells = {}
|
|
@@ -169,7 +346,7 @@ def state_of(obj, stores):
|
|
|
169
346
|
if f.get('opt'): c[f['name'] + '_has'] = x is not None
|
|
170
347
|
c[f['name']] = (x if x is not None else (f['vals'][0] if f.get('choice') else 0)) if f.get('choice') else enc_num(0 if x is None else x)
|
|
171
348
|
cells[h] = c
|
|
172
|
-
else: cells[h] = {'value': v if l.get('choice') else enc_num(v)}
|
|
349
|
+
else: cells[h] = {'value': v if l.get('choice') else (v.decode('latin-1') if isinstance(v, (bytes, bytearray)) else v) if l.get('str') else enc_num(int(v) if isinstance(v, bool) else v)}
|
|
173
350
|
s[l['name']] = cells
|
|
174
351
|
continue
|
|
175
352
|
v = walk(obj, l['path'])
|
|
@@ -187,6 +364,7 @@ def state_of(obj, stores):
|
|
|
187
364
|
s[l['name']] = cells
|
|
188
365
|
# A store's key no template names: the code keeps state the rule has no place for.
|
|
189
366
|
for name, st in stores.items():
|
|
367
|
+
if isinstance(st, ORMTable): continue
|
|
190
368
|
tpls = [l['tpl'] for l in S['leaves'] if l.get('store') == name]
|
|
191
369
|
for key in st.data:
|
|
192
370
|
if not any(tpl_match(t, key) is not None for t in tpls): raise ValueError(f"the store {name} holds {key!r}, a key no template of the rule names")
|
|
@@ -204,6 +382,9 @@ def set_state(obj, stores, state):
|
|
|
204
382
|
k = l['kind']
|
|
205
383
|
if k in ('frame', 'none'): continue
|
|
206
384
|
v = state.get(l['name'])
|
|
385
|
+
if l.get('orm'):
|
|
386
|
+
orm_restore(stores[l['name']], v or {})
|
|
387
|
+
continue
|
|
207
388
|
if l.get('store'):
|
|
208
389
|
st = stores[l['store']]
|
|
209
390
|
pre, _, post = l['tpl'].partition('{}')
|
|
@@ -211,9 +392,12 @@ def set_state(obj, stores, state):
|
|
|
211
392
|
for h, c in (v or {}).items():
|
|
212
393
|
at = pre + h + post if '{}' in l['tpl'] else l['tpl']
|
|
213
394
|
if l.get('json'): st.data[at] = json.dumps({f['name']: (c[f['name']] if f.get('choice') else num_in(c[f['name']], False)) for f in l['json'] if not f.get('out') and (not f.get('opt') or c.get(f['name'] + '_has'))})
|
|
214
|
-
else: st.data[at] = c['value'] if l.get('choice') else num_in(c['value'], l.get('float'))
|
|
395
|
+
else: st.data[at] = c['value'] if l.get('choice') or l.get('str') else num_in(c['value'], l.get('float'))
|
|
215
396
|
continue
|
|
216
|
-
if k == 'num':
|
|
397
|
+
if k == 'num':
|
|
398
|
+
t = l.get('t') or {}
|
|
399
|
+
if t.get('k') == 'opt': t = t['of']
|
|
400
|
+
put(obj, l['path'], datetime_in(v, t['unit']) if t.get('unit', '').startswith('datetime-') else num_in(v, l.get('float')))
|
|
217
401
|
elif k in ('str', 'choice', 'bool'): put(obj, l['path'], v.encode('latin-1') if k == 'str' and is_bytes(l) and isinstance(v, str) else v)
|
|
218
402
|
elif k == 'map':
|
|
219
403
|
d = {}
|
|
@@ -241,10 +425,11 @@ def frames(obj):
|
|
|
241
425
|
REAL = {}
|
|
242
426
|
def tracer(frame, event, arg):
|
|
243
427
|
f = frame.f_code.co_filename
|
|
244
|
-
if f not in REAL: REAL[f] = os.path.realpath(f)
|
|
245
|
-
|
|
428
|
+
if f not in REAL: REAL[f] = S['sources'].get(os.path.realpath(f))
|
|
429
|
+
source = REAL[f]
|
|
430
|
+
if source is not None:
|
|
246
431
|
def local(fr, ev, a):
|
|
247
|
-
if ev == 'line': HIT.add(fr.f_lineno)
|
|
432
|
+
if ev == 'line': HIT.add((source, fr.f_lineno))
|
|
248
433
|
return local
|
|
249
434
|
return local
|
|
250
435
|
return None
|
|
@@ -259,7 +444,10 @@ class Clock:
|
|
|
259
444
|
class _Now(datetime.datetime):
|
|
260
445
|
"""datetime.datetime with now() the request's time (local, naive, as the code's own now())."""
|
|
261
446
|
@classmethod
|
|
262
|
-
def now(cls, tz=None):
|
|
447
|
+
def now(cls, tz=None):
|
|
448
|
+
if tz is None and (time_module.timezone != 0 or time_module.altzone != 0):
|
|
449
|
+
raise ValueError('naive datetime clocks require a UTC process timezone')
|
|
450
|
+
return datetime.datetime.fromtimestamp(NOW[0], tz)
|
|
263
451
|
# (where it is seen anyway, a type read while the clock is pinned, pydantic's: a datetime)
|
|
264
452
|
@classmethod
|
|
265
453
|
def __get_pydantic_core_schema__(cls, source, handler): return handler(datetime.datetime)
|
|
@@ -319,9 +507,11 @@ def raises_here(key):
|
|
|
319
507
|
f = sys._getframe(1)
|
|
320
508
|
while f is not None and os.path.realpath(f.f_code.co_filename) == os.path.realpath(__file__): f = f.f_back
|
|
321
509
|
if f is None: return True
|
|
322
|
-
here
|
|
510
|
+
here = os.path.relpath(os.path.realpath(f.f_code.co_filename), S['root']).replace(os.sep, '/')
|
|
511
|
+
line = f.f_lineno
|
|
323
512
|
for site in a['at']:
|
|
324
|
-
|
|
513
|
+
parts = site['p'].rsplit(':', 2)
|
|
514
|
+
file, l0 = parts[0], int(parts[1])
|
|
325
515
|
l1 = int(site['end'].split(':')[0]) if site.get('end') and site['end'].split(':')[0].isdigit() else l0
|
|
326
516
|
if file == here and l0 <= line <= l1: return True
|
|
327
517
|
return False
|
|
@@ -356,15 +546,41 @@ def patch_target(p):
|
|
|
356
546
|
return o, p['path'][-1]
|
|
357
547
|
|
|
358
548
|
def hello(req):
|
|
549
|
+
def has_naive(v):
|
|
550
|
+
if isinstance(v, dict):
|
|
551
|
+
return v.get('unit') == 'datetime-naive' or v.get('time') == 'datetime-naive' or any(has_naive(x) for x in v.values())
|
|
552
|
+
return isinstance(v, list) and any(has_naive(x) for x in v)
|
|
553
|
+
if (req.get('naiveUtc') or has_naive(req)) and (time_module.timezone != 0 or time_module.altzone != 0):
|
|
554
|
+
raise ValueError('stated naive datetime values require a UTC process timezone')
|
|
359
555
|
S.update(req)
|
|
360
556
|
S['path'] = os.path.realpath(req['path'])
|
|
557
|
+
S['root'] = os.path.realpath(req['root'])
|
|
558
|
+
# Only files the reader actually used, including imported bases; never arbitrary repository imports.
|
|
559
|
+
S['sources'] = {os.path.realpath(os.path.join(S['root'], name)): name for name, _ in req['arms']}
|
|
560
|
+
REAL.clear(); HIT.clear()
|
|
361
561
|
sys.path.insert(0, req['root'])
|
|
562
|
+
if os.environ.get('DJANGO_SETTINGS_MODULE'):
|
|
563
|
+
import django
|
|
564
|
+
django.setup()
|
|
362
565
|
S['mod'] = importlib.import_module(req['module'])
|
|
363
566
|
mod = S['mod']
|
|
364
567
|
pin_clocks(req['root'])
|
|
365
568
|
S['self_stubs'] = []
|
|
366
569
|
for a in req['answers']:
|
|
367
570
|
p = a['patch']
|
|
571
|
+
# (an effect: a call recorded, nothing run, None returned)
|
|
572
|
+
if a.get('effect'):
|
|
573
|
+
def rec(key, is_async):
|
|
574
|
+
def f(*x, **k): EFF[key] = True
|
|
575
|
+
async def af(*x, **k): EFF[key] = True
|
|
576
|
+
return af if is_async else f
|
|
577
|
+
f = rec(a['key'], a['async'])
|
|
578
|
+
if p.get('store'): continue
|
|
579
|
+
if p.get('self'): S['self_stubs'].append((p['self'], {**a, 'effect_fn': f})); continue
|
|
580
|
+
o, name = patch_target(p)
|
|
581
|
+
raw = inspect.getattr_static(o, name, None)
|
|
582
|
+
setattr(o, name, staticmethod(f) if isinstance(raw, staticmethod) else f)
|
|
583
|
+
continue
|
|
368
584
|
if p.get('store'): continue
|
|
369
585
|
if p.get('self'): S['self_stubs'].append((p['self'], a))
|
|
370
586
|
else:
|
|
@@ -380,6 +596,9 @@ def hello(req):
|
|
|
380
596
|
def make(args):
|
|
381
597
|
global OBJ_STORES
|
|
382
598
|
OBJ_STORES = {}
|
|
599
|
+
for leaf in S['leaves']:
|
|
600
|
+
if leaf.get('orm'): OBJ_STORES[leaf['name']] = ORMTable(leaf)
|
|
601
|
+
for table in OBJ_STORES.values(): table.install()
|
|
383
602
|
if S['cls'] is None: obj = types.SimpleNamespace()
|
|
384
603
|
else:
|
|
385
604
|
kw = fixed_args(args, {})
|
|
@@ -387,8 +606,13 @@ def make(args):
|
|
|
387
606
|
try:
|
|
388
607
|
with pinned(): obj = run(S['cls'](**kw))
|
|
389
608
|
finally: sys.settrace(None)
|
|
390
|
-
for name, a in S['self_stubs']: obj.__dict__[name] = stub(a['key'], a['async'], getattr(obj, name) if a.get('pass') else None)
|
|
609
|
+
for name, a in S['self_stubs']: obj.__dict__[name] = a['effect_fn'] if a.get('effect_fn') else stub(a['key'], a['async'], getattr(obj, name) if a.get('pass') else None)
|
|
391
610
|
for name in S.get('inject') or []: setattr(obj, name, build({'store': name}, OBJ_STORES))
|
|
611
|
+
# (fields stated: the object configured so after its constructor, as the claim says)
|
|
612
|
+
for f, v in (S.get('fields') or {}).items(): setattr(obj, f, v)
|
|
613
|
+
# (a module's object stated as a store: the store in its place, this object's while it runs)
|
|
614
|
+
for g in S.get('globals') or []: build({'store': g['name']}, OBJ_STORES)
|
|
615
|
+
set_globals(OBJ_STORES)
|
|
392
616
|
i = len(OBJS) + 1
|
|
393
617
|
OBJS[i] = (obj, OBJ_STORES)
|
|
394
618
|
return i
|
|
@@ -396,14 +620,25 @@ def make(args):
|
|
|
396
620
|
def run(x):
|
|
397
621
|
return S['loop'].run_until_complete(x) if inspect.isawaitable(x) else x
|
|
398
622
|
|
|
623
|
+
def set_globals(stores):
|
|
624
|
+
for table in stores.values():
|
|
625
|
+
if isinstance(table, ORMTable): table.install()
|
|
626
|
+
for g in S.get('globals') or []: setattr(importlib.import_module(g['mod']), g['name'], stores[g['name']])
|
|
627
|
+
|
|
399
628
|
def call(req):
|
|
400
629
|
obj, stores = OBJS[req['id']]
|
|
401
630
|
global OBJ_STORES
|
|
402
631
|
OBJ_STORES = stores
|
|
632
|
+
set_globals(stores)
|
|
403
633
|
NOW[0] = int(req.get('now') or 0)
|
|
634
|
+
for store in stores.values():
|
|
635
|
+
if isinstance(store, ORMSession): store.loaded.clear(); store.added.clear()
|
|
404
636
|
CUR.clear(); CUR.update(req.get('answers') or {})
|
|
637
|
+
EFF.clear()
|
|
405
638
|
fn = getattr(obj, req['m']) if S['cls'] is not None else getattr(S['mod'], req['m'])
|
|
406
|
-
kwargs = fixed_args(req['a'], {})
|
|
639
|
+
try: kwargs = fixed_args(req['a'], {})
|
|
640
|
+
except OverflowError as e:
|
|
641
|
+
return {'outside': f'argument outside the declared runtime domain: {e}'}
|
|
407
642
|
before = frames(obj if S['cls'] is not None else None)
|
|
408
643
|
snap = state_of(obj, stores) if S.get('discard') and S['cls'] is not None else None
|
|
409
644
|
sys.settrace(tracer)
|
|
@@ -422,7 +657,7 @@ def call(req):
|
|
|
422
657
|
after = frames(obj if S['cls'] is not None else None)
|
|
423
658
|
for k in before:
|
|
424
659
|
if after.get(k) != before[k]: return {'frame': k}
|
|
425
|
-
return {'out': tag(out), **({'err': err} if err is not None else {})}
|
|
660
|
+
return {'out': tag(out), **({'err': err} if err is not None else {}), **({'effects': dict(EFF)} if EFF else {})}
|
|
426
661
|
|
|
427
662
|
def main():
|
|
428
663
|
fin = open(sys.argv[1], 'r'); fout = open(sys.argv[2], 'w')
|
|
@@ -434,7 +669,11 @@ def main():
|
|
|
434
669
|
if op == 'hello': res = hello(req)
|
|
435
670
|
elif op == 'new':
|
|
436
671
|
try: res = {'id': make(req['a'])}
|
|
437
|
-
except Exception as e:
|
|
672
|
+
except Exception as e:
|
|
673
|
+
res = {'err': f"{type(e).__name__}: {e}"[:300]}
|
|
674
|
+
if os.environ.get('GDP_HARNESS_LOG'):
|
|
675
|
+
import traceback
|
|
676
|
+
with open(os.environ['GDP_HARNESS_LOG'], 'a') as f: traceback.print_exc(file=f)
|
|
438
677
|
elif op == 'at':
|
|
439
678
|
try:
|
|
440
679
|
i = make(req['a'])
|
|
@@ -445,7 +684,7 @@ def main():
|
|
|
445
684
|
obj, stores = OBJS[req['id']]
|
|
446
685
|
res = {'state': state_of(obj, stores)}
|
|
447
686
|
elif op == 'call': res = call(req)
|
|
448
|
-
elif op == 'coverage': res = {'hit':
|
|
687
|
+
elif op == 'coverage': res = {'hit': sorted(HIT)}
|
|
449
688
|
else: res = {'error': f"no op {op}"}
|
|
450
689
|
except Exception as e:
|
|
451
690
|
res = {'error': f"{type(e).__name__}: {e}"[:500]}
|