Resolve command script under dashboard subpath #62
|
|
@ -160,7 +160,7 @@ textarea { resize: vertical; min-height: 120px; }
|
||||||
<div class="footer">Creative AI-imbued UI • stackchain-dashboard</div>
|
<div class="footer">Creative AI-imbued UI • stackchain-dashboard</div>
|
||||||
|
|
||||||
<script src="/static/markdown.js"></script>
|
<script src="/static/markdown.js"></script>
|
||||||
<script src="/static/commands.js"></script>
|
<script src="static/commands.js"></script>
|
||||||
<script>
|
<script>
|
||||||
(function(){
|
(function(){
|
||||||
const qs = (s, el=document) => el.querySelector(s);
|
const qs = (s, el=document) => el.querySelector(s);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,24 @@
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from html.parser import HTMLParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = Path(__file__).parents[1] / "frontend" / "commands.js"
|
FRONTEND = Path(__file__).parents[1] / "frontend"
|
||||||
|
COMMANDS = FRONTEND / "commands.js"
|
||||||
|
|
||||||
|
|
||||||
|
class ScriptSourceParser(HTMLParser):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.sources = []
|
||||||
|
|
||||||
|
def handle_starttag(self, tag, attrs):
|
||||||
|
if tag == "script":
|
||||||
|
source = dict(attrs).get("src")
|
||||||
|
if source:
|
||||||
|
self.sources.append(source)
|
||||||
|
|
||||||
|
|
||||||
def test_filtered_command_runs_the_matching_action():
|
def test_filtered_command_runs_the_matching_action():
|
||||||
|
|
@ -21,3 +36,13 @@ if (action !== 'refresh') throw new Error(`expected refresh, got ${{action}}`);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
subprocess.run(["node", "-e", script], check=True, capture_output=True, text=True)
|
subprocess.run(["node", "-e", script], check=True, capture_output=True, text=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_command_script_resolves_inside_dashboard_subpath():
|
||||||
|
parser = ScriptSourceParser()
|
||||||
|
parser.feed((FRONTEND / "index.html").read_text())
|
||||||
|
command_source = next(source for source in parser.sources if source.endswith("commands.js"))
|
||||||
|
|
||||||
|
assert urljoin(
|
||||||
|
"https://forge.alexanderwhitestone.com/dashboard/", command_source
|
||||||
|
) == "https://forge.alexanderwhitestone.com/dashboard/static/commands.js"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user