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

ossia / score / 35310244323

18 Sep 2026 05:17AM UTC coverage: 39.902% (+2.2%) from 37.724%
35310244323

push

github

jcelerier
tests: include CommandDispatcher where JsLibraryScriptSavingTest uses it

ee4b67af6f added the test with a CommandDispatcher<> but without its header,
relying on it arriving transitively. The Coverage build compiles with clang-19
at gnu++23 and does not get it that way:

  JsLibraryScriptSavingTest.cpp:70:3: error: no template named 'CommandDispatcher'

This has been broken since 2026-09-13 and was hidden behind the boost download
failure, which stopped that job before it ever reached the compile.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1e2ZdUQh7Srmv6BGVakrQ

114906 of 287968 relevant lines covered (39.9%)

77906.02 hits per line

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

88.2
/src/plugins/score-plugin-js/JS/ApplicationPlugin.cpp
1
#include "ApplicationPlugin.hpp"
2

3
#include <JS/DocumentPlugin.hpp>
4
#include <JS/Qml/DeviceContext.hpp>
5
#include <JS/Qml/EditContext.hpp>
6
#include <JS/Qml/Utils.hpp>
7
#include <JS/Qml/ViewContext.hpp>
8
#include <Library/LibrarySettings.hpp>
9
#include <LocalTree/LocalTreeDocumentPlugin.hpp>
10

11
#include <core/application/ApplicationInterface.hpp>
12
#include <core/document/Document.hpp>
13
#include <core/presenter/DocumentManager.hpp>
14

15
#include <ossia/detail/thread.hpp>
16

17
#include <ossia-qt/invoke.hpp>
18
#include <ossia-qt/qml_protocols.hpp>
19

20
#include <QCommandLineParser>
21
#include <QFile>
22
#include <QFileInfo>
23
#include <QString>
24

25
#if __has_include(<QQuickWindow>)
26
#include <QGuiApplication>
27
#include <QQuickItem>
28
#include <QQuickWindow>
29
#endif
30

31
#if SCORE_HAS_GPU_JS
32
#include <Gfx/Settings/Model.hpp>
33
#endif
34

35
#include <ossia/network/context.hpp>
36

37
namespace JS
38
{
39
// Check whether the input is a script, or a file path.
40
// An existing file always wins: a real path may legitimately contain
41
// characters (parentheses, braces, ...) that also occur in inline source,
42
// so the file-existence check must come FIRST. Only when the input is not
43
// an existing file do we fall back to the inline-source heuristic.
44
static bool stringIsScript(const QString& input)
78✔
45
{
46
  if(input.isEmpty())
78✔
47
    return false;
×
48

49
  if(QFileInfo fileInfo{input}; fileInfo.exists() && fileInfo.isFile())
152✔
50
    return false;
74✔
51

52
  if(input.length() > 4096)
4✔
53
    return true;
×
54

55
  for(QChar ch : input)
56✔
56
  {
57
    const char16_t c = ch.unicode();
55✔
58
    if(c == '\n' || c == '\r' || c == ';' || c == '{' || c == '}' || c == '('
55✔
59
       || c == ')')
55✔
60
      return true;
3✔
61
  }
62

63
  return false;
1✔
64
}
78✔
65

66
ApplicationPlugin::ApplicationPlugin(const score::GUIApplicationContext& ctx)
1,661✔
67
    : score::GUIApplicationPlugin{ctx}
1,661✔
68
{
1,661✔
69
#if __has_include(<QQuickWindow>) && !defined(__APPLE__)
70
  // Crisp text in every QML UI: distance-field rendering looks blurry at the small
71
  // font sizes our panels use, native glyph rendering matches the rest of score.
72
  // Not on macOS: https://qt-project.atlassian.net/browse/QTBUG-150490
73
  QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
1,661✔
74
#endif
75

76
  // For the console
77
  m_consoleEngine.globalObject().setProperty("Score", m_consoleEngine.newQObject(new EditJsContext));
1,661✔
78
  m_consoleEngine.globalObject().setProperty("Util", m_consoleEngine.newQObject(new JsUtils));
1,661✔
79
  m_consoleEngine.globalObject().setProperty(
3,322✔
80
      "System", m_consoleEngine.newQObject(new JsSystem));
1,661✔
81
  m_consoleEngine.globalObject().setProperty(
3,322✔
82
      "Library", m_consoleEngine.newQObject(new JsLibrary));
1,661✔
83
  m_consoleEngine.globalObject().setProperty("Device", m_consoleEngine.newQObject(new DeviceContext{m_consoleEngine}));
1,661✔
84
  m_consoleEngine.globalObject().setProperty("View", m_consoleEngine.newQObject(new JsViewContext));
1,661✔
85
  connect(&m_consoleEngine, &QQmlEngine::exit, this, [&](int retCode) {
1,705✔
86
    for(auto& doc : score::GUIAppContext().docManager.documents())
88✔
87
      doc->commandStack().markCurrentIndexAsSaved();
44✔
88
    // quit() is exit(0), which discarded the code Qt.exit() was given: a script
89
    // could stop the app but never report that it had failed.
90
    qApp->exit(retCode);
44✔
91
    QTimer::singleShot(
44✔
92
        500, [] { score::GUIApplicationInterface::instance().forceExit(); });
11✔
93
  });
44✔
94
  m_asioContext = std::make_shared<ossia::net::network_context>();
1,661✔
95
  m_processMessages = true;
1,661✔
96
  m_consoleEngine.globalObject().setProperty(
3,322✔
97
      "Protocols",
1,661✔
98
      m_consoleEngine.newQObject(new ossia::qt::qml_protocols{m_asioContext, this}));
1,661✔
99
  m_asioThread = std::thread{[this] {
3,322✔
100
    ossia::set_thread_name("ossia app asio");
1,661✔
101
    while(m_processMessages)
3,322✔
102
    {
103
      m_asioContext->run();
1,661✔
104
    }
105
  }};
1,661✔
106

107
  // For scripts of processes that run in the ui thread:
108
  m_scriptProcessUIEngine.globalObject().setProperty(
3,322✔
109
      "Util", m_scriptProcessUIEngine.newQObject(new JsUtils));
1,661✔
110
  m_scriptProcessUIEngine.globalObject().setProperty(
3,322✔
111
      "System", m_scriptProcessUIEngine.newQObject(new JsSystem));
1,661✔
112
  m_scriptProcessUIEngine.globalObject().setProperty(
3,322✔
113
      "Library", m_scriptProcessUIEngine.newQObject(new JsLibrary));
1,661✔
114
  m_scriptProcessUIEngine.globalObject().setProperty(
3,322✔
115
      "View", m_scriptProcessUIEngine.newQObject(new JsViewContext));
1,661✔
116

117
  // Command-line option parsing
118
  QCommandLineParser parser;
1,661✔
119

120
  QCommandLineOption script_opt(
1,661✔
121
      "script", QCoreApplication::translate("js", "script"), "Script", "");
1,661✔
122
  parser.addOption(script_opt);
1,661✔
123

124
  parser.parse(ctx.applicationSettings.arguments);
1,661✔
125
  for(const QString& script : parser.values(script_opt))
1,739✔
126
  {
127
    if(script.isEmpty())
78✔
128
      continue;
×
129

130
    if(stringIsScript(script))
78✔
131
    {
132
      this->m_start_scripts.push_back(StartScript{.source = script});
3✔
133
      continue;
134
    }
135

136
    QFile f{script};
75✔
137
    if(!f.open(QIODevice::ReadOnly))
75✔
138
    {
139
      qCritical() << "--script: cannot open" << script << ":" << f.errorString();
1✔
140
      this->m_start_script_failed = true;
1✔
141
      continue;
1✔
142
    }
143

144
    const QFileInfo fi{f};
74✔
145
    StartScript s;
74✔
146
    s.name = script;
74✔
147
    s.file = fi.canonicalFilePath();
74✔
148
    s.dir = fi.canonicalPath();
74✔
149
    // .mjs is what the rest of score calls an ES module (see the library's
150
    // ModuleLibraryHandler); only those go through importModule().
151
    s.module = fi.suffix().compare(QStringLiteral("mjs"), Qt::CaseInsensitive) == 0;
74✔
152
    if(!s.module)
74✔
153
      s.source = QString::fromUtf8(f.readAll());
70✔
154

155
    this->m_start_scripts.push_back(std::move(s));
74✔
156
  }
75✔
157
}
×
158

159
QJSValue ApplicationPlugin::importModule(QQmlEngine& engine, const QString& path)
4✔
160
{
161
  QJSValue mod = engine.importModule(path);
4✔
162
  if(mod.isError())
4✔
163
    return mod;
1✔
164

165
  if(auto init = mod.property("initialize"); init.isCallable())
5✔
166
    if(const auto res = init.call(); res.isError())
4✔
167
      return res;
1✔
168

169
  engine.globalObject().setProperty(QFileInfo{path}.baseName(), mod);
2✔
170
  return mod;
2✔
171
}
4✔
172

173
void ApplicationPlugin::on_newDocument(score::Document& doc)
527✔
174
{
175
  score::addDocumentPlugin<DocumentPlugin>(doc);
527✔
176
}
527✔
177

178
ApplicationPlugin::~ApplicationPlugin()
3,318✔
179
{
1,659✔
180
  m_processMessages = false;
1,659✔
181
  m_asioContext->context.stop();
1,659✔
182
  m_asioThread.join();
1,659✔
183
}
3,318✔
184

185
void ApplicationPlugin::on_createdDocument(score::Document& doc)
551✔
186
{
187
  // Local Tree
188
  LocalTree::DocumentPlugin* lt = doc.context().findPlugin<LocalTree::DocumentPlugin>();
551✔
189
  if(lt)
551✔
190
  {
191
    auto& root = lt->device().get_root_node();
551✔
192

193
    auto node = root.create_child("script");
551✔
194
    auto address = node->create_parameter(ossia::val_type::STRING);
551✔
195
    address->set_value(std::string{});
551✔
196
    address->set_access(ossia::access_mode::SET);
551✔
197
    address->add_callback([&](const ossia::value& v) {
609✔
198
      ossia::qt::run_async(
58✔
199
          this, [this, str = QString::fromStdString(ossia::convert<std::string>(v))] {
116✔
200
        auto res = m_consoleEngine.evaluate(str);
58✔
201
        if(res.isError())
58✔
202
        {
203
          qDebug() << res.toString();
×
204
        }
×
205
      });
58✔
206
    });
58✔
207
  }
551✔
208

209
  // Custom data
210
  if(auto customData = doc.context().findPlugin<DocumentPlugin>(); !customData)
551✔
211
    score::addDocumentPlugin<DocumentPlugin>(doc);
×
212

213
  if(m_start_script_failed)
551✔
214
  {
215
    qGuiApp->exit(2);
1✔
216
    return;
1✔
217
  }
218

219
  if(!m_start_scripts.empty())
550✔
220
  {
221
    QTimer::singleShot(100, this, [this] {
147✔
222
      for(const StartScript& s : m_start_scripts)
141✔
223
      {
224
        if(!s.dir.isEmpty())
73✔
225
          m_consoleEngine.addImportPath(s.dir);
71✔
226

227
        // Report a throwing --script: an unresolvable readFile returns an empty
228
        // string and eval("") is a no-op, so the process would otherwise exit
229
        // reporting success and a harness could not tell that from a pass.
230
        const auto res = s.module ? importModule(m_consoleEngine, s.file)
73✔
231
                                  : m_consoleEngine.evaluate(s.source, s.name);
69✔
232
        if(res.isError())
73✔
233
        {
234
          qCritical().noquote()
8✔
235
              << "--script:"
4✔
236
              << (s.name.isEmpty() ? QStringLiteral("<inline>") : s.name) << "line"
4✔
237
              << res.property("lineNumber").toInt() << ":" << res.toString();
4✔
238
          qGuiApp->exit(3);
4✔
239
          return;
4✔
240
        }
241
      }
73✔
242
    });
72✔
243
  }
75✔
244
}
551✔
245
void ApplicationPlugin::afterStartup()
76✔
246
{
247
  // Dummy engine setup for JS processes
248
  // eng.importModule(
249
  //     "/home/jcelerier/Documents/ossia/score/packages/default/Scripts/include/"
250
  //     "tonal.mjs");
251
  for(auto& p : this->context.settings<Library::Settings::Model>().getIncludePaths())
76✔
252
  {
253
    m_scriptProcessUIEngine.addImportPath(p);
×
254
    // The console engine runs --script, the console panel and every library
255
    // .mjs; without this they could not import what a JS process can, which
256
    // made the same `import` line work in a process and fail in a script.
257
    m_consoleEngine.addImportPath(p);
×
258
  }
259

260
#if __has_include(<QQuickWindow>)
261
  if(QFileInfo f{context.applicationSettings.ui}; f.isFile())
80✔
262
  {
263
    m_comp = new QQmlComponent{&m_consoleEngine, f.absoluteFilePath(), this};
4✔
264

265
    if(auto obj = m_comp->create())
4✔
266
    {
267
      if(auto item = qobject_cast<QQuickItem*>(obj))
1✔
268
      {
269
        m_window = new QQuickWindow{};
×
270
  // QWidget gets these from QWidgetPrivate::adjustFlags; a bare QQuickWindow
271
  // does not, and on platforms where Qt draws the chrome itself (wasm) that
272
  // leaves the window with no title bar, close or minimise button.
273
  m_window->setFlags(
×
274
      m_window->flags() | Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint
×
275
      | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint
×
276
      | Qt::WindowMaximizeButtonHint);
×
277
#if defined(__EMSCRIPTEN__)
278
  // Qt for wasm reports ShowIsFullScreen unconditionally, so QWindow::show()
279
  // turns into showFullScreen() for every top level: the requested size is
280
  // discarded and the full-screen state suppresses the frame. Only Qt::Dialog
281
  // and Qt::Popup opt out (QWasmIntegration::defaultWindowState).
282
  m_window->setFlags(m_window->flags() | Qt::Dialog);
283
#endif
284
        m_window->setWidth(640);
×
285
        m_window->setHeight(480);
×
286
        item->setParentItem(m_window->contentItem());
×
287
#if defined(__EMSCRIPTEN__)
288
        m_window->showNormal();
289
#else
290
        m_window->show();
×
291
#endif
292
        return;
×
293
      }
294
    }
1✔
295
    else
296
    {
297
      qDebug() << m_comp->errorString();
3✔
298
      qGuiApp->exit(1);
3✔
299
    }
300
    delete m_comp;
4✔
301
  }
4✔
302
#endif
303
}
76✔
304
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc